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/. */
|
2013-06-19 18:24:37 +04:00
|
|
|
|
|
|
|
#include "mozilla/dom/HTMLFormElement.h"
|
2013-10-03 11:11:26 +04:00
|
|
|
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include <utility>
|
|
|
|
|
2013-10-03 11:11:26 +04:00
|
|
|
#include "jsapi.h"
|
2019-12-05 07:44:32 +03:00
|
|
|
#include "mozilla/BasePrincipal.h"
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include "mozilla/BinarySearch.h"
|
2013-10-03 11:11:26 +04:00
|
|
|
#include "mozilla/ContentEvents.h"
|
2014-03-18 08:48:21 +04:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2014-04-03 08:18:36 +04:00
|
|
|
#include "mozilla/EventStates.h"
|
2019-05-31 17:33:33 +03:00
|
|
|
#include "mozilla/dom/BindContext.h"
|
2018-08-16 05:22:30 +03:00
|
|
|
#include "mozilla/dom/CustomEvent.h"
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2013-10-03 11:11:26 +04:00
|
|
|
#include "mozilla/dom/HTMLFormControlsCollection.h"
|
2013-06-19 18:24:37 +04:00
|
|
|
#include "mozilla/dom/HTMLFormElementBinding.h"
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include "mozilla/dom/nsCSPContext.h"
|
|
|
|
#include "mozilla/dom/nsCSPUtils.h"
|
|
|
|
#include "mozilla/dom/nsMixedContentBlocker.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCOMArray.h"
|
|
|
|
#include "nsContentList.h"
|
|
|
|
#include "nsContentUtils.h"
|
2020-02-11 04:22:29 +03:00
|
|
|
#include "nsDocShell.h"
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include "nsError.h"
|
2006-12-26 20:47:52 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2019-06-04 20:27:43 +03:00
|
|
|
#include "nsHTMLDocument.h"
|
2001-04-17 14:02:11 +04:00
|
|
|
#include "nsIFormControlFrame.h"
|
2003-09-26 23:26:17 +04:00
|
|
|
#include "nsInterfaceHashtable.h"
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include "nsPresContext.h"
|
2015-04-15 19:47:03 +03:00
|
|
|
#include "nsQueryObject.h"
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsTArray.h"
|
2002-02-16 04:19:24 +03:00
|
|
|
|
|
|
|
// form submission
|
2016-06-16 10:24:16 +03:00
|
|
|
#include "HTMLFormSubmissionConstants.h"
|
2016-01-07 22:30:36 +03:00
|
|
|
#include "mozilla/dom/FormData.h"
|
2019-09-09 16:53:27 +03:00
|
|
|
#include "mozilla/dom/FormDataEvent.h"
|
2020-02-11 15:46:54 +03:00
|
|
|
#include "mozilla/dom/SubmitEvent.h"
|
2015-01-15 22:01:10 +03:00
|
|
|
#include "mozilla/Telemetry.h"
|
2001-11-02 10:40:01 +03:00
|
|
|
#include "nsIFormSubmitObserver.h"
|
2002-02-16 04:19:24 +03:00
|
|
|
#include "nsIObserverService.h"
|
2002-07-18 09:09:10 +04:00
|
|
|
#include "nsCategoryManagerUtils.h"
|
2002-02-16 04:19:24 +03:00
|
|
|
#include "nsISimpleEnumerator.h"
|
|
|
|
#include "nsRange.h"
|
2015-07-10 19:15:46 +03:00
|
|
|
#include "nsIScriptError.h"
|
2002-02-16 04:19:24 +03:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
|
|
|
#include "nsNetUtil.h"
|
2015-07-07 05:17:00 +03:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2002-03-13 09:08:56 +03:00
|
|
|
#include "nsIWebProgress.h"
|
|
|
|
#include "nsIDocShell.h"
|
2015-06-03 23:47:56 +03:00
|
|
|
#include "nsIPrompt.h"
|
2015-01-15 22:01:10 +03:00
|
|
|
#include "nsISecurityUITelemetry.h"
|
|
|
|
#include "nsIStringBundle.h"
|
2002-02-16 04:19:24 +03:00
|
|
|
|
2002-03-07 23:53:40 +03:00
|
|
|
// radio buttons
|
2013-03-28 23:41:32 +04:00
|
|
|
#include "mozilla/dom/HTMLInputElement.h"
|
2002-03-07 23:53:40 +03:00
|
|
|
#include "nsIRadioVisitor.h"
|
2014-07-16 20:44:19 +04:00
|
|
|
#include "RadioNodeList.h"
|
2000-04-19 11:49:07 +04:00
|
|
|
|
2004-10-31 22:58:10 +03:00
|
|
|
#include "nsLayoutUtils.h"
|
|
|
|
|
2008-04-11 21:29:06 +04:00
|
|
|
#include "mozAutoDocUpdate.h"
|
2008-10-22 18:31:14 +04:00
|
|
|
#include "nsIHTMLCollection.h"
|
2008-04-11 21:29:06 +04:00
|
|
|
|
2010-08-21 22:52:49 +04:00
|
|
|
#include "nsIConstraintValidation.h"
|
2010-08-21 22:51:38 +04:00
|
|
|
|
2012-08-20 22:34:32 +04:00
|
|
|
#include "nsSandboxFlags.h"
|
2010-10-29 23:49:42 +04:00
|
|
|
|
2013-06-18 16:53:23 +04:00
|
|
|
// images
|
|
|
|
#include "mozilla/dom/HTMLImageElement.h"
|
2017-09-28 07:03:58 +03:00
|
|
|
#include "mozilla/dom/HTMLButtonElement.h"
|
2013-06-18 16:53:23 +04:00
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
// construction, destruction
|
2014-08-01 21:02:30 +04:00
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(Form)
|
2013-06-19 18:24:37 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2010-10-25 16:17:38 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static const uint8_t NS_FORM_AUTOCOMPLETE_ON = 1;
|
|
|
|
static const uint8_t NS_FORM_AUTOCOMPLETE_OFF = 0;
|
2010-09-14 21:55:16 +04:00
|
|
|
|
|
|
|
static const nsAttrValue::EnumTable kFormAutocompleteTable[] = {
|
|
|
|
{"on", NS_FORM_AUTOCOMPLETE_ON},
|
|
|
|
{"off", NS_FORM_AUTOCOMPLETE_OFF},
|
2016-09-07 05:20:17 +03:00
|
|
|
{nullptr, 0}};
|
2010-09-14 21:55:16 +04:00
|
|
|
// Default autocomplete value is 'on'.
|
|
|
|
static const nsAttrValue::EnumTable* kFormDefaultAutocomplete =
|
|
|
|
&kFormAutocompleteTable[0];
|
|
|
|
|
2018-09-21 23:45:49 +03:00
|
|
|
HTMLFormElement::HTMLFormElement(
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
|
|
|
|
: nsGenericHTMLElement(std::move(aNodeInfo)),
|
2015-01-07 08:39:46 +03:00
|
|
|
mControls(new HTMLFormControlsCollection(this)),
|
2014-08-06 17:31:21 +04:00
|
|
|
mSelectedRadioButtons(2),
|
|
|
|
mRequiredRadioButtonCounts(2),
|
|
|
|
mValueMissingRadioGroups(2),
|
2012-07-30 18:20:58 +04:00
|
|
|
mPendingSubmission(nullptr),
|
|
|
|
mSubmittingRequest(nullptr),
|
|
|
|
mDefaultSubmitElement(nullptr),
|
|
|
|
mFirstSubmitInElements(nullptr),
|
|
|
|
mFirstSubmitNotInElements(nullptr),
|
2014-08-06 17:31:21 +04:00
|
|
|
mImageNameLookupTable(FORM_CONTROL_LIST_HASHTABLE_LENGTH),
|
|
|
|
mPastNameLookupTable(FORM_CONTROL_LIST_HASHTABLE_LENGTH),
|
2018-12-16 12:21:16 +03:00
|
|
|
mSubmitPopupState(PopupBlocker::openAbused),
|
2010-11-24 02:50:19 +03:00
|
|
|
mInvalidElementsCount(0),
|
2019-07-01 13:06:16 +03:00
|
|
|
mFormNumber(-1),
|
2017-07-06 23:57:24 +03:00
|
|
|
mGeneratingSubmit(false),
|
|
|
|
mGeneratingReset(false),
|
|
|
|
mIsSubmitting(false),
|
|
|
|
mDeferSubmission(false),
|
|
|
|
mNotifiedObservers(false),
|
|
|
|
mNotifiedObserversResult(false),
|
2019-09-09 16:53:27 +03:00
|
|
|
mEverTriedInvalidSubmit(false),
|
2019-11-20 22:39:38 +03:00
|
|
|
mIsConstructingEntryList(false),
|
|
|
|
mIsFiringSubmissionEvents(false) {
|
2016-08-09 23:23:40 +03:00
|
|
|
// We start out valid.
|
|
|
|
AddStatesSilently(NS_EVENT_STATE_VALID);
|
2004-05-19 00:58:12 +04:00
|
|
|
}
|
2002-03-07 23:53:40 +03:00
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
HTMLFormElement::~HTMLFormElement() {
|
2004-05-19 00:58:12 +04:00
|
|
|
if (mControls) {
|
2006-02-08 01:10:29 +03:00
|
|
|
mControls->DropFormReference();
|
2004-05-19 00:58:12 +04:00
|
|
|
}
|
2013-06-18 16:53:23 +04:00
|
|
|
|
|
|
|
Clear();
|
2004-05-19 00:58:12 +04:00
|
|
|
}
|
|
|
|
|
1998-09-23 21:16:51 +04:00
|
|
|
// nsISupports
|
1998-09-02 04:56:01 +04:00
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLFormElement)
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLFormElement,
|
2007-03-08 14:17:16 +03:00
|
|
|
nsGenericHTMLElement)
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mControls)
|
2013-06-18 16:53:23 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mImageNameLookupTable)
|
2013-06-18 16:54:27 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPastNameLookupTable)
|
2015-07-28 04:45:12 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSelectedRadioButtons)
|
2007-03-08 14:17:16 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLFormElement,
|
2013-06-18 16:53:23 +04:00
|
|
|
nsGenericHTMLElement)
|
|
|
|
tmp->Clear();
|
2016-07-22 23:19:52 +03:00
|
|
|
tmp->mExpandoAndGeneration.OwnerUnlinked();
|
2013-06-18 16:53:23 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2017-09-01 02:29:22 +03:00
|
|
|
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(HTMLFormElement,
|
|
|
|
nsGenericHTMLElement, nsIForm,
|
|
|
|
nsIWebProgressListener,
|
|
|
|
nsIRadioGroupContainer)
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2016-10-13 09:33:53 +03:00
|
|
|
// EventTarget
|
|
|
|
void HTMLFormElement::AsyncEventRunning(AsyncEventDispatcher* aEvent) {
|
|
|
|
if (mFormPasswordEventDispatcher == aEvent) {
|
|
|
|
mFormPasswordEventDispatcher = nullptr;
|
|
|
|
}
|
|
|
|
}
|
1998-09-23 21:16:51 +04:00
|
|
|
|
2014-08-01 21:02:30 +04:00
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLFormElement)
|
1998-09-02 04:56:01 +04:00
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
nsIHTMLCollection* HTMLFormElement::Elements() { return mControls; }
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
nsresult HTMLFormElement::BeforeSetAttr(int32_t aNamespaceID, nsAtom* aName,
|
2017-06-07 20:28:20 +03:00
|
|
|
const nsAttrValueOrString* aValue,
|
|
|
|
bool aNotify) {
|
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
|
|
|
if (aName == nsGkAtoms::action || aName == nsGkAtoms::target) {
|
2017-09-28 22:09:56 +03:00
|
|
|
// Don't forget we've notified the password manager already if the
|
|
|
|
// page sets the action/target in the during submit. (bug 343182)
|
|
|
|
bool notifiedObservers = mNotifiedObservers;
|
|
|
|
ForgetCurrentSubmission();
|
|
|
|
mNotifiedObservers = notifiedObservers;
|
2002-11-30 03:01:21 +03:00
|
|
|
}
|
2002-08-20 06:35:39 +04:00
|
|
|
}
|
2017-06-07 20:28:20 +03:00
|
|
|
|
|
|
|
return nsGenericHTMLElement::BeforeSetAttr(aNamespaceID, aName, aValue,
|
|
|
|
aNotify);
|
1998-10-20 21:07:23 +04:00
|
|
|
}
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
nsresult HTMLFormElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
|
2017-05-19 00:09:01 +03:00
|
|
|
const nsAttrValue* aValue,
|
2017-10-10 00:33:38 +03:00
|
|
|
const nsAttrValue* aOldValue,
|
|
|
|
nsIPrincipal* aSubjectPrincipal,
|
|
|
|
bool aNotify) {
|
2010-12-18 02:26:24 +03:00
|
|
|
if (aName == nsGkAtoms::novalidate && aNameSpaceID == kNameSpaceID_None) {
|
|
|
|
// Update all form elements states because they might be [no longer]
|
|
|
|
// affected by :-moz-ui-valid or :-moz-ui-invalid.
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0, length = mControls->mElements.Length(); i < length;
|
2011-06-01 05:46:57 +04:00
|
|
|
++i) {
|
|
|
|
mControls->mElements[i]->UpdateState(true);
|
|
|
|
}
|
2010-12-18 02:26:24 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0, length = mControls->mNotInElements.Length();
|
2011-06-01 05:46:57 +04:00
|
|
|
i < length; ++i) {
|
|
|
|
mControls->mNotInElements[i]->UpdateState(true);
|
2010-12-18 02:26:24 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-19 00:09:01 +03:00
|
|
|
return nsGenericHTMLElement::AfterSetAttr(
|
2017-10-10 00:33:38 +03:00
|
|
|
aNameSpaceID, aName, aValue, aOldValue, aSubjectPrincipal, aNotify);
|
2010-12-18 02:26:24 +03:00
|
|
|
}
|
|
|
|
|
2018-02-23 21:28:08 +03:00
|
|
|
void HTMLFormElement::GetAutocomplete(nsAString& aValue) {
|
|
|
|
GetEnumAttr(nsGkAtoms::autocomplete, kFormDefaultAutocomplete->tag, aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLFormElement::GetEnctype(nsAString& aValue) {
|
|
|
|
GetEnumAttr(nsGkAtoms::enctype, kFormDefaultEnctype->tag, aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLFormElement::GetMethod(nsAString& aValue) {
|
|
|
|
GetEnumAttr(nsGkAtoms::method, kFormDefaultMethod->tag, aValue);
|
|
|
|
}
|
2001-11-02 10:40:01 +03:00
|
|
|
|
2019-11-20 19:14:39 +03:00
|
|
|
// https://html.spec.whatwg.org/multipage/forms.html#concept-form-submit
|
|
|
|
void HTMLFormElement::MaybeSubmit(Element* aSubmitter) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (aSubmitter) {
|
|
|
|
nsCOMPtr<nsIFormControl> fc = do_QueryInterface(aSubmitter);
|
|
|
|
MOZ_ASSERT(fc);
|
|
|
|
MOZ_ASSERT(fc->IsSubmitControl(), "aSubmitter is not a submit control?");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// 1-4 of
|
|
|
|
// https://html.spec.whatwg.org/multipage/forms.html#concept-form-submit
|
|
|
|
Document* doc = GetComposedDoc();
|
|
|
|
if (mIsConstructingEntryList || !doc ||
|
|
|
|
(doc->GetSandboxFlags() & SANDBOXED_FORMS)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-20 22:39:38 +03:00
|
|
|
// 6.1. If form's firing submission events is true, then return.
|
|
|
|
if (mIsFiringSubmissionEvents) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 6.2. Set form's firing submission events to true.
|
|
|
|
AutoRestore<bool> resetFiringSubmissionEventsFlag(mIsFiringSubmissionEvents);
|
|
|
|
mIsFiringSubmissionEvents = true;
|
|
|
|
|
2019-11-20 19:14:39 +03:00
|
|
|
// 6.3. If the submitter element's no-validate state is false, then
|
|
|
|
// interactively validate the constraints of form and examine the result.
|
|
|
|
// If the result is negative (i.e., the constraint validation concluded
|
|
|
|
// that there were invalid fields and probably informed the user of this)
|
|
|
|
bool noValidateState =
|
|
|
|
HasAttr(kNameSpaceID_None, nsGkAtoms::novalidate) ||
|
|
|
|
(aSubmitter &&
|
|
|
|
aSubmitter->HasAttr(kNameSpaceID_None, nsGkAtoms::formnovalidate));
|
|
|
|
if (!noValidateState && !CheckValidFormSubmission()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If |PresShell::Destroy| has been called due to handling the event the pres
|
|
|
|
// context will return a null pres shell. See bug 125624. Using presShell to
|
|
|
|
// dispatch the event. It makes sure that event is not handled if the window
|
|
|
|
// is being destroyed.
|
|
|
|
if (RefPtr<PresShell> presShell = doc->GetPresShell()) {
|
2020-02-11 15:46:54 +03:00
|
|
|
SubmitEventInit init;
|
|
|
|
init.mBubbles = true;
|
|
|
|
init.mCancelable = true;
|
|
|
|
init.mSubmitter =
|
|
|
|
aSubmitter ? nsGenericHTMLElement::FromNode(aSubmitter) : nullptr;
|
|
|
|
RefPtr<SubmitEvent> event =
|
|
|
|
SubmitEvent::Constructor(this, NS_LITERAL_STRING("submit"), init);
|
|
|
|
event->SetTrusted(true);
|
2019-11-20 19:14:39 +03:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2020-02-11 15:46:54 +03:00
|
|
|
presShell->HandleDOMEventWithTarget(this, event, &status);
|
2019-11-20 19:14:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLFormElement::MaybeReset(Element* aSubmitter) {
|
|
|
|
// If |PresShell::Destroy| has been called due to handling the event the pres
|
|
|
|
// context will return a null pres shell. See bug 125624. Using presShell to
|
|
|
|
// dispatch the event. It makes sure that event is not handled if the window
|
|
|
|
// is being destroyed.
|
|
|
|
if (RefPtr<PresShell> presShell = OwnerDoc()->GetPresShell()) {
|
|
|
|
InternalFormEvent event(true, eFormReset);
|
|
|
|
event.mOriginator = aSubmitter;
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
presShell->HandleDOMEventWithTarget(this, &event, &status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
void HTMLFormElement::Submit(ErrorResult& aRv) {
|
2002-05-15 05:24:59 +04:00
|
|
|
// Send the submit event
|
2005-11-09 01:45:49 +03:00
|
|
|
if (mPendingSubmission) {
|
|
|
|
// aha, we have a pending submission that was not flushed
|
|
|
|
// (this happens when form.submit() is called twice)
|
|
|
|
// we have to delete it and build a new one since values
|
|
|
|
// might have changed inbetween (we emulate IE here, that's all)
|
2012-07-30 18:20:58 +04:00
|
|
|
mPendingSubmission = nullptr;
|
1998-09-23 21:16:51 +04:00
|
|
|
}
|
2005-11-09 01:45:49 +03:00
|
|
|
|
2020-02-11 15:46:54 +03:00
|
|
|
aRv = DoSubmit();
|
2013-06-19 18:24:37 +04:00
|
|
|
}
|
|
|
|
|
2019-12-03 13:13:41 +03:00
|
|
|
// https://html.spec.whatwg.org/multipage/forms.html#dom-form-requestsubmit
|
|
|
|
void HTMLFormElement::RequestSubmit(nsGenericHTMLElement* aSubmitter,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
// 1. If submitter is not null, then:
|
|
|
|
if (aSubmitter) {
|
|
|
|
nsCOMPtr<nsIFormControl> fc = do_QueryObject(aSubmitter);
|
|
|
|
|
|
|
|
// 1.1. If submitter is not a submit button, then throw a TypeError.
|
|
|
|
if (!fc || !fc->IsSubmitControl()) {
|
2020-03-07 00:04:58 +03:00
|
|
|
aRv.ThrowTypeError("The submitter is not a submit button.");
|
2019-12-03 13:13:41 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 1.2. If submitter's form owner is not this form element, then throw a
|
|
|
|
// "NotFoundError" DOMException.
|
|
|
|
if (fc->GetFormElement() != this) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_NOT_FOUND_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 2. Otherwise, set submitter to this form element.
|
|
|
|
// 3. Submit this form element, from submitter.
|
|
|
|
MaybeSubmit(aSubmitter);
|
|
|
|
}
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
void HTMLFormElement::Reset() {
|
2015-09-02 09:08:00 +03:00
|
|
|
InternalFormEvent event(true, eFormReset);
|
2014-03-18 08:48:21 +04:00
|
|
|
EventDispatcher::Dispatch(static_cast<nsIContent*>(this), nullptr, &event);
|
2010-08-21 22:51:38 +04:00
|
|
|
}
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
bool HTMLFormElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
2017-11-02 06:35:52 +03:00
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
2013-06-19 18:24:37 +04:00
|
|
|
nsAttrValue& aResult) {
|
2005-11-29 19:37:15 +03:00
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::method) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return aResult.ParseEnumValue(aValue, kFormMethodTable, false);
|
2005-11-29 19:37:15 +03:00
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::enctype) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return aResult.ParseEnumValue(aValue, kFormEnctypeTable, false);
|
2005-11-29 19:37:15 +03:00
|
|
|
}
|
2010-09-14 21:55:16 +04:00
|
|
|
if (aAttribute == nsGkAtoms::autocomplete) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return aResult.ParseEnumValue(aValue, kFormAutocompleteTable, false);
|
2010-09-14 21:55:16 +04:00
|
|
|
}
|
1998-09-23 21:16:51 +04:00
|
|
|
}
|
2004-03-04 05:06:28 +03:00
|
|
|
|
2005-11-29 19:37:15 +03:00
|
|
|
return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
2017-11-02 06:35:52 +03:00
|
|
|
aMaybeScriptedPrincipal, aResult);
|
1998-09-02 04:56:01 +04:00
|
|
|
}
|
|
|
|
|
Bug 1555216 - Change the signature of BindToTree to be (BindContext&, nsINode& aParentNode). r=bzbarsky
BindContext was going to have way more information at first, but then I realized
that most of the things I wanted to know were basically a flag away using the
parent node.
Still I think it's worth it, now experimenting with BindToTree will only mean
adding a field to a struct that's included from a couple cpp files, instead of a
massive pain.
I also think this is clearer, and doing this highlights quite a few
inconsistencies in our code which I've left untouched, but commented with
FIXMEs.
Steps are:
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsresult BindToTree(Document\* aDocument, nsIContent\* aParent,#nsresult BindToTree(BindContext\&, nsINode\& aParent)#g' $file; done
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's# nsIContent\* aBindingParent) override#override#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(Document\* aDocument, nsIContent\* aParent,#::BindToTree(BindContext\& aContext, nsINode\& aParent)#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsIContent\* aBindingParent)##g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(aDocument, aParent, aBindingParent)#::BindToTree(aContext, aParent)#g' $file; done
$ ./mach clang-format
Then manual fixups.
Depends on D32948
Differential Revision: https://phabricator.services.mozilla.com/D32949
2019-05-29 07:27:04 +03:00
|
|
|
nsresult HTMLFormElement::BindToTree(BindContext& aContext, nsINode& aParent) {
|
|
|
|
nsresult rv = nsGenericHTMLElement::BindToTree(aContext, aParent);
|
2005-04-06 03:54:35 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2019-05-31 17:33:33 +03:00
|
|
|
if (IsInUncomposedDoc() && aContext.OwnerDoc().IsHTMLOrXHTML()) {
|
|
|
|
aContext.OwnerDoc().AsHTMLDocument()->AddedForm();
|
2002-07-17 02:38:51 +04:00
|
|
|
}
|
2005-04-06 03:54:35 +04:00
|
|
|
|
|
|
|
return rv;
|
2002-07-17 02:38:51 +04:00
|
|
|
}
|
|
|
|
|
2013-06-18 16:53:23 +04:00
|
|
|
template <typename T>
|
|
|
|
static void MarkOrphans(const nsTArray<T*>& aArray) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t length = aArray.Length();
|
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
2009-10-30 04:49:11 +03:00
|
|
|
aArray[i]->SetFlags(MAYBE_ORPHAN_FORM_ELEMENT);
|
2007-11-07 20:01:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-29 20:14:13 +04:00
|
|
|
static void CollectOrphans(nsINode* aRemovalRoot,
|
|
|
|
const nsTArray<nsGenericHTMLFormElement*>& aArray
|
2007-11-07 20:01:23 +03:00
|
|
|
#ifdef DEBUG
|
2018-03-14 23:42:25 +03:00
|
|
|
,
|
|
|
|
HTMLFormElement* aThisForm
|
2007-11-07 20:01:23 +03:00
|
|
|
#endif
|
|
|
|
) {
|
2011-06-01 05:46:57 +04:00
|
|
|
// Put a script blocker around all the notifications we're about to do.
|
2011-06-01 01:38:25 +04:00
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
2010-11-24 02:50:19 +03:00
|
|
|
|
2007-11-07 20:01:23 +03:00
|
|
|
// Walk backwards so that if we remove elements we can just keep iterating
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t length = aArray.Length();
|
|
|
|
for (uint32_t i = length; i > 0; --i) {
|
2009-10-30 04:49:11 +03:00
|
|
|
nsGenericHTMLFormElement* node = aArray[i - 1];
|
2007-11-07 20:01:23 +03:00
|
|
|
|
|
|
|
// Now if MAYBE_ORPHAN_FORM_ELEMENT is not set, that would mean that the
|
|
|
|
// node is in fact a descendant of the form and hence should stay in the
|
|
|
|
// form. If it _is_ set, then we need to check whether the node is a
|
2013-06-18 16:53:23 +04:00
|
|
|
// descendant of aRemovalRoot. If it is, we leave it in the form.
|
2007-11-07 20:01:23 +03:00
|
|
|
#ifdef DEBUG
|
2011-09-29 10:19:26 +04:00
|
|
|
bool removed = false;
|
2007-11-07 20:01:23 +03:00
|
|
|
#endif
|
|
|
|
if (node->HasFlag(MAYBE_ORPHAN_FORM_ELEMENT)) {
|
|
|
|
node->UnsetFlags(MAYBE_ORPHAN_FORM_ELEMENT);
|
2019-07-12 16:10:28 +03:00
|
|
|
if (!node->IsInclusiveDescendantOf(aRemovalRoot)) {
|
2017-05-02 00:10:00 +03:00
|
|
|
node->ClearForm(true, false);
|
2010-09-10 09:08:56 +04:00
|
|
|
|
2011-06-01 05:46:57 +04:00
|
|
|
// When a form control loses its form owner, its state can change.
|
|
|
|
node->UpdateState(true);
|
2007-11-07 20:01:23 +03:00
|
|
|
#ifdef DEBUG
|
2011-10-17 18:59:28 +04:00
|
|
|
removed = true;
|
2007-11-07 20:01:23 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (!removed) {
|
2018-03-14 23:42:25 +03:00
|
|
|
HTMLFormElement* form = node->GetForm();
|
2007-11-07 20:01:23 +03:00
|
|
|
NS_ASSERTION(form == aThisForm, "How did that happen?");
|
|
|
|
}
|
|
|
|
#endif /* DEBUG */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-18 16:53:23 +04:00
|
|
|
static void CollectOrphans(nsINode* aRemovalRoot,
|
|
|
|
const nsTArray<HTMLImageElement*>& aArray
|
|
|
|
#ifdef DEBUG
|
2018-03-14 23:42:25 +03:00
|
|
|
,
|
|
|
|
HTMLFormElement* aThisForm
|
2013-06-18 16:53:23 +04:00
|
|
|
#endif
|
|
|
|
) {
|
|
|
|
// Walk backwards so that if we remove elements we can just keep iterating
|
|
|
|
uint32_t length = aArray.Length();
|
|
|
|
for (uint32_t i = length; i > 0; --i) {
|
|
|
|
HTMLImageElement* node = aArray[i - 1];
|
|
|
|
|
|
|
|
// Now if MAYBE_ORPHAN_FORM_ELEMENT is not set, that would mean that the
|
|
|
|
// node is in fact a descendant of the form and hence should stay in the
|
|
|
|
// form. If it _is_ set, then we need to check whether the node is a
|
|
|
|
// descendant of aRemovalRoot. If it is, we leave it in the form.
|
|
|
|
#ifdef DEBUG
|
|
|
|
bool removed = false;
|
|
|
|
#endif
|
|
|
|
if (node->HasFlag(MAYBE_ORPHAN_FORM_ELEMENT)) {
|
|
|
|
node->UnsetFlags(MAYBE_ORPHAN_FORM_ELEMENT);
|
2019-07-12 16:10:28 +03:00
|
|
|
if (!node->IsInclusiveDescendantOf(aRemovalRoot)) {
|
2013-06-18 16:53:23 +04:00
|
|
|
node->ClearForm(true);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
removed = true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (!removed) {
|
2018-03-14 23:42:25 +03:00
|
|
|
HTMLFormElement* form = node->GetForm();
|
2013-06-18 16:53:23 +04:00
|
|
|
NS_ASSERTION(form == aThisForm, "How did that happen?");
|
|
|
|
}
|
|
|
|
#endif /* DEBUG */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-29 01:47:08 +03:00
|
|
|
void HTMLFormElement::UnbindFromTree(bool aNullParent) {
|
2018-07-04 19:18:57 +03:00
|
|
|
// Note, this is explicitly using uncomposed doc, since we count
|
|
|
|
// only forms in document.
|
2019-06-04 20:27:43 +03:00
|
|
|
RefPtr<Document> oldDocument = GetUncomposedDoc();
|
2005-04-06 03:54:35 +04:00
|
|
|
|
2007-11-07 20:01:23 +03:00
|
|
|
// Mark all of our controls as maybe being orphans
|
|
|
|
MarkOrphans(mControls->mElements);
|
|
|
|
MarkOrphans(mControls->mNotInElements);
|
2013-06-18 16:53:23 +04:00
|
|
|
MarkOrphans(mImageElements);
|
2007-11-07 20:01:23 +03:00
|
|
|
|
2019-05-29 01:47:08 +03:00
|
|
|
nsGenericHTMLElement::UnbindFromTree(aNullParent);
|
2005-04-06 03:54:35 +04:00
|
|
|
|
2007-11-07 20:01:23 +03:00
|
|
|
nsINode* ancestor = this;
|
|
|
|
nsINode* cur;
|
|
|
|
do {
|
2012-10-09 16:31:24 +04:00
|
|
|
cur = ancestor->GetParentNode();
|
2007-11-07 20:01:23 +03:00
|
|
|
if (!cur) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ancestor = cur;
|
|
|
|
} while (1);
|
2016-04-12 14:02:42 +03:00
|
|
|
|
2007-11-07 20:01:23 +03:00
|
|
|
CollectOrphans(ancestor, mControls->mElements
|
|
|
|
#ifdef DEBUG
|
|
|
|
,
|
|
|
|
this
|
2013-06-18 16:53:23 +04:00
|
|
|
#endif
|
2007-11-07 20:01:23 +03:00
|
|
|
);
|
|
|
|
CollectOrphans(ancestor, mControls->mNotInElements
|
|
|
|
#ifdef DEBUG
|
|
|
|
,
|
|
|
|
this
|
2013-06-18 16:53:23 +04:00
|
|
|
#endif
|
|
|
|
);
|
|
|
|
CollectOrphans(ancestor, mImageElements
|
|
|
|
#ifdef DEBUG
|
|
|
|
,
|
|
|
|
this
|
|
|
|
#endif
|
2007-11-07 20:01:23 +03:00
|
|
|
);
|
|
|
|
|
2019-06-04 20:27:43 +03:00
|
|
|
if (oldDocument && oldDocument->IsHTMLOrXHTML()) {
|
|
|
|
oldDocument->AsHTMLDocument()->RemovedForm();
|
2013-06-18 16:53:23 +04:00
|
|
|
}
|
2005-04-06 03:54:35 +04:00
|
|
|
ForgetCurrentSubmission();
|
|
|
|
}
|
2002-07-17 02:38:51 +04:00
|
|
|
|
2016-10-21 05:11:07 +03:00
|
|
|
void HTMLFormElement::GetEventTargetParent(EventChainPreVisitor& aVisitor) {
|
2011-10-17 18:59:28 +04:00
|
|
|
aVisitor.mWantsWillHandleEvent = true;
|
2019-07-09 21:44:43 +03:00
|
|
|
if (aVisitor.mEvent->mOriginalTarget == static_cast<nsIContent*>(this)) {
|
2015-08-22 04:34:51 +03:00
|
|
|
uint32_t msg = aVisitor.mEvent->mMessage;
|
2015-09-02 09:08:00 +03:00
|
|
|
if (msg == eFormSubmit) {
|
2006-03-07 20:08:51 +03:00
|
|
|
if (mGeneratingSubmit) {
|
2011-10-17 18:59:28 +04:00
|
|
|
aVisitor.mCanHandle = false;
|
2018-04-05 20:42:41 +03:00
|
|
|
return;
|
2006-03-07 20:08:51 +03:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
mGeneratingSubmit = true;
|
2002-05-13 21:22:30 +04:00
|
|
|
|
2006-03-07 20:08:51 +03:00
|
|
|
// let the form know that it needs to defer the submission,
|
|
|
|
// that means that if there are scripted submissions, the
|
|
|
|
// latest one will be deferred until after the exit point of the handler.
|
2011-10-17 18:59:28 +04:00
|
|
|
mDeferSubmission = true;
|
2015-09-02 09:08:00 +03:00
|
|
|
} else if (msg == eFormReset) {
|
2006-03-07 20:08:51 +03:00
|
|
|
if (mGeneratingReset) {
|
2011-10-17 18:59:28 +04:00
|
|
|
aVisitor.mCanHandle = false;
|
2018-04-05 20:42:41 +03:00
|
|
|
return;
|
2006-03-07 20:08:51 +03:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
mGeneratingReset = true;
|
2001-04-24 09:18:10 +04:00
|
|
|
}
|
2002-12-04 02:06:34 +03:00
|
|
|
}
|
2018-04-05 20:42:41 +03:00
|
|
|
nsGenericHTMLElement::GetEventTargetParent(aVisitor);
|
2006-03-07 20:08:51 +03:00
|
|
|
}
|
2000-08-18 09:18:01 +04:00
|
|
|
|
2014-03-18 08:48:20 +04:00
|
|
|
void HTMLFormElement::WillHandleEvent(EventChainPostVisitor& aVisitor) {
|
2008-04-18 02:15:07 +04:00
|
|
|
// If this is the bubble stage and there is a nested form below us which
|
|
|
|
// received a submit event we do *not* want to handle the submit event
|
|
|
|
// for this form too.
|
2015-09-02 09:08:00 +03:00
|
|
|
if ((aVisitor.mEvent->mMessage == eFormSubmit ||
|
2015-09-02 09:08:00 +03:00
|
|
|
aVisitor.mEvent->mMessage == eFormReset) &&
|
2012-12-16 05:26:03 +04:00
|
|
|
aVisitor.mEvent->mFlags.mInBubblingPhase &&
|
2016-04-18 19:33:23 +03:00
|
|
|
aVisitor.mEvent->mOriginalTarget != static_cast<nsIContent*>(this)) {
|
2016-03-17 05:17:42 +03:00
|
|
|
aVisitor.mEvent->StopPropagation();
|
2008-04-18 02:15:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-18 08:48:20 +04:00
|
|
|
nsresult HTMLFormElement::PostHandleEvent(EventChainPostVisitor& aVisitor) {
|
2019-07-09 21:44:43 +03:00
|
|
|
if (aVisitor.mEvent->mOriginalTarget == static_cast<nsIContent*>(this)) {
|
2015-08-26 15:56:59 +03:00
|
|
|
EventMessage msg = aVisitor.mEvent->mMessage;
|
2015-09-02 09:08:00 +03:00
|
|
|
if (msg == eFormSubmit) {
|
2006-03-07 20:08:51 +03:00
|
|
|
// let the form know not to defer subsequent submissions
|
2011-10-17 18:59:28 +04:00
|
|
|
mDeferSubmission = false;
|
2006-03-07 20:08:51 +03:00
|
|
|
}
|
2000-08-18 09:18:01 +04:00
|
|
|
|
2006-03-07 20:08:51 +03:00
|
|
|
if (aVisitor.mEventStatus == nsEventStatus_eIgnore) {
|
|
|
|
switch (msg) {
|
2020-02-11 15:46:54 +03:00
|
|
|
case eFormReset: {
|
|
|
|
DoReset();
|
|
|
|
break;
|
|
|
|
}
|
2015-09-02 09:08:00 +03:00
|
|
|
case eFormSubmit: {
|
2020-02-11 15:46:54 +03:00
|
|
|
if (mPendingSubmission) {
|
2002-12-04 02:06:34 +03:00
|
|
|
// tell the form to forget a possible pending submission.
|
|
|
|
// the reason is that the script returned true (the event was
|
|
|
|
// ignored) so if there is a stored submission, it will miss
|
|
|
|
// the name/value of the submitting element, thus we need
|
|
|
|
// to forget it and the form element will build a new one
|
2012-07-30 18:20:58 +04:00
|
|
|
mPendingSubmission = nullptr;
|
2002-12-04 02:06:34 +03:00
|
|
|
}
|
2020-02-11 15:46:54 +03:00
|
|
|
DoSubmit(aVisitor.mDOMEvent);
|
2015-08-26 15:56:59 +03:00
|
|
|
break;
|
2002-12-04 02:06:34 +03:00
|
|
|
}
|
2015-08-26 15:56:59 +03:00
|
|
|
default:
|
|
|
|
break;
|
2000-08-18 09:18:01 +04:00
|
|
|
}
|
2002-12-04 02:06:34 +03:00
|
|
|
} else {
|
2015-09-02 09:08:00 +03:00
|
|
|
if (msg == eFormSubmit) {
|
2002-12-14 05:38:17 +03:00
|
|
|
// tell the form to flush a possible pending submission.
|
|
|
|
// the reason is that the script returned false (the event was
|
|
|
|
// not ignored) so if there is a stored submission, it needs to
|
|
|
|
// be submitted immediatelly.
|
|
|
|
FlushPendingSubmission();
|
|
|
|
}
|
2000-08-18 09:18:01 +04:00
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2015-09-02 09:08:00 +03:00
|
|
|
if (msg == eFormSubmit) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mGeneratingSubmit = false;
|
2015-09-02 09:08:00 +03:00
|
|
|
} else if (msg == eFormReset) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mGeneratingReset = false;
|
2006-03-07 20:08:51 +03:00
|
|
|
}
|
2001-04-24 09:18:10 +04:00
|
|
|
}
|
2006-03-07 20:08:51 +03:00
|
|
|
return NS_OK;
|
1998-09-02 04:56:01 +04:00
|
|
|
}
|
1998-09-23 21:16:51 +04:00
|
|
|
|
2020-02-11 15:46:54 +03:00
|
|
|
nsresult HTMLFormElement::DoReset() {
|
2001-04-24 09:18:10 +04:00
|
|
|
// Make sure the presentation is up-to-date
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* doc = GetComposedDoc();
|
2004-10-11 20:14:27 +04:00
|
|
|
if (doc) {
|
2017-01-05 10:31:56 +03:00
|
|
|
doc->FlushPendingNotifications(FlushType::ContentAndNotify);
|
2001-04-24 09:18:10 +04:00
|
|
|
}
|
|
|
|
|
2018-01-09 11:37:02 +03:00
|
|
|
mEverTriedInvalidSubmit = false;
|
2001-11-02 10:40:01 +03:00
|
|
|
// JBK walk the elements[] array instead of form frame controls - bug 34297
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t numElements = GetElementCount();
|
|
|
|
for (uint32_t elementX = 0; elementX < numElements; ++elementX) {
|
2009-10-30 04:49:11 +03:00
|
|
|
// Hold strong ref in case the reset does something weird
|
|
|
|
nsCOMPtr<nsIFormControl> controlNode = GetElementAt(elementX);
|
2001-11-02 10:40:01 +03:00
|
|
|
if (controlNode) {
|
|
|
|
controlNode->Reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-08-20 06:35:39 +04:00
|
|
|
#define NS_ENSURE_SUBMIT_SUCCESS(rv) \
|
|
|
|
if (NS_FAILED(rv)) { \
|
|
|
|
ForgetCurrentSubmission(); \
|
|
|
|
return rv; \
|
2002-03-13 09:08:56 +03:00
|
|
|
}
|
2002-11-30 03:01:21 +03:00
|
|
|
|
2020-02-11 15:46:54 +03:00
|
|
|
nsresult HTMLFormElement::DoSubmit(Event* aEvent) {
|
|
|
|
Document* doc = GetComposedDoc();
|
|
|
|
NS_ASSERTION(doc, "Should never get here without a current doc");
|
|
|
|
|
|
|
|
// Make sure the presentation is up-to-date
|
|
|
|
if (doc) {
|
|
|
|
doc->FlushPendingNotifications(FlushType::ContentAndNotify);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't submit if we're not in a document or if we're in
|
|
|
|
// a sandboxed frame and form submit is disabled.
|
|
|
|
if (mIsConstructingEntryList || !doc ||
|
|
|
|
(doc->GetSandboxFlags() & SANDBOXED_FORMS)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-11-07 09:44:02 +03:00
|
|
|
|
2002-03-13 09:08:56 +03:00
|
|
|
if (mIsSubmitting) {
|
2007-11-07 09:44:02 +03:00
|
|
|
NS_WARNING("Preventing double form submission");
|
2002-03-13 09:08:56 +03:00
|
|
|
// XXX Should this return an error?
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mark us as submitting so that we don't try to submit again
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsSubmitting = true;
|
2002-08-20 06:35:39 +04:00
|
|
|
NS_ASSERTION(!mWebProgress && !mSubmittingRequest,
|
|
|
|
"Web progress / submitting request should not exist here!");
|
2002-02-16 04:19:24 +03:00
|
|
|
|
2016-06-16 10:24:16 +03:00
|
|
|
nsAutoPtr<HTMLFormSubmission> submission;
|
2010-02-25 08:58:16 +03:00
|
|
|
|
2002-11-30 03:01:21 +03:00
|
|
|
//
|
|
|
|
// prepare the submission object
|
|
|
|
//
|
2010-08-20 21:47:30 +04:00
|
|
|
nsresult rv = BuildSubmission(getter_Transfers(submission), aEvent);
|
2019-09-09 16:53:27 +03:00
|
|
|
|
|
|
|
// Don't raise an error if form cannot navigate.
|
2019-09-09 16:53:34 +03:00
|
|
|
if (StaticPrefs::dom_formdata_event_enabled() &&
|
|
|
|
rv == NS_ERROR_NOT_AVAILABLE) {
|
2019-09-09 16:53:27 +03:00
|
|
|
mIsSubmitting = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-08-20 21:47:30 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsSubmitting = false;
|
2010-08-20 21:47:30 +04:00
|
|
|
return rv;
|
|
|
|
}
|
2004-09-04 23:28:46 +04:00
|
|
|
|
2004-10-11 20:14:27 +04:00
|
|
|
// XXXbz if the script global is that for an sXBL/XBL2 doc, it won't
|
|
|
|
// be a window...
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowOuter* window = OwnerDoc()->GetWindow();
|
2004-09-04 23:28:46 +04:00
|
|
|
if (window) {
|
2018-12-16 12:21:16 +03:00
|
|
|
mSubmitPopupState = PopupBlocker::GetPopupControlState();
|
2004-09-04 23:28:46 +04:00
|
|
|
} else {
|
2018-12-16 12:21:16 +03:00
|
|
|
mSubmitPopupState = PopupBlocker::openAbused;
|
2004-09-04 23:28:46 +04:00
|
|
|
}
|
|
|
|
|
2016-04-12 14:02:42 +03:00
|
|
|
if (mDeferSubmission) {
|
2002-12-04 02:06:34 +03:00
|
|
|
// we are in an event handler, JS submitted so we have to
|
2002-11-30 03:01:21 +03:00
|
|
|
// defer this submission. let's remember it and return
|
|
|
|
// without submitting
|
|
|
|
mPendingSubmission = submission;
|
|
|
|
// ensure reentrancy
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsSubmitting = false;
|
2016-04-12 14:02:42 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2002-11-30 03:01:21 +03:00
|
|
|
// perform the submission
|
|
|
|
//
|
2016-04-12 14:02:42 +03:00
|
|
|
return SubmitSubmission(submission);
|
2002-11-30 03:01:21 +03:00
|
|
|
}
|
|
|
|
|
2016-06-16 10:24:16 +03:00
|
|
|
nsresult HTMLFormElement::BuildSubmission(HTMLFormSubmission** aFormSubmission,
|
2020-02-11 15:46:54 +03:00
|
|
|
Event* aEvent) {
|
2002-12-14 05:38:17 +03:00
|
|
|
NS_ASSERTION(!mPendingSubmission, "tried to build two submissions!");
|
2002-11-30 03:01:21 +03:00
|
|
|
|
2020-02-11 15:46:57 +03:00
|
|
|
// Get the submitter element
|
|
|
|
nsGenericHTMLElement* submitter = nullptr;
|
2002-02-16 04:19:24 +03:00
|
|
|
if (aEvent) {
|
2020-02-11 15:46:54 +03:00
|
|
|
SubmitEvent* submitEvent = aEvent->AsSubmitEvent();
|
|
|
|
if (submitEvent) {
|
2020-02-11 15:46:57 +03:00
|
|
|
submitter = submitEvent->GetSubmitter();
|
2002-02-16 04:19:24 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-30 03:01:21 +03:00
|
|
|
nsresult rv;
|
|
|
|
|
2019-09-09 16:53:27 +03:00
|
|
|
//
|
|
|
|
// Walk over the form elements and call SubmitNamesValues() on them to get
|
|
|
|
// their data.
|
|
|
|
//
|
|
|
|
auto encoding = GetSubmitEncoding()->OutputEncoding();
|
|
|
|
RefPtr<FormData> formData =
|
2020-02-11 15:46:57 +03:00
|
|
|
new FormData(GetOwnerGlobal(), encoding, submitter);
|
2019-09-09 16:53:27 +03:00
|
|
|
rv = ConstructEntryList(formData);
|
|
|
|
NS_ENSURE_SUBMIT_SUCCESS(rv);
|
|
|
|
|
|
|
|
// Step 9. If form cannot navigate, then return.
|
|
|
|
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#form-submission-algorithm
|
2019-09-09 16:53:34 +03:00
|
|
|
if (StaticPrefs::dom_formdata_event_enabled() && !GetComposedDoc()) {
|
2019-09-09 16:53:27 +03:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2002-02-16 04:19:24 +03:00
|
|
|
//
|
|
|
|
// Get the submission object
|
|
|
|
//
|
2020-02-11 15:46:57 +03:00
|
|
|
rv = HTMLFormSubmission::GetFromForm(this, submitter, encoding,
|
2016-06-16 10:25:48 +03:00
|
|
|
aFormSubmission);
|
2002-03-13 09:08:56 +03:00
|
|
|
NS_ENSURE_SUBMIT_SUCCESS(rv);
|
2002-02-16 04:19:24 +03:00
|
|
|
|
|
|
|
//
|
|
|
|
// Dump the data into the submission object
|
|
|
|
//
|
2019-09-09 16:53:27 +03:00
|
|
|
rv = formData->CopySubmissionDataTo(*aFormSubmission);
|
2002-03-13 09:08:56 +03:00
|
|
|
NS_ENSURE_SUBMIT_SUCCESS(rv);
|
2002-02-16 04:19:24 +03:00
|
|
|
|
2002-11-30 03:01:21 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-06-16 10:24:16 +03:00
|
|
|
nsresult HTMLFormElement::SubmitSubmission(
|
|
|
|
HTMLFormSubmission* aFormSubmission) {
|
2002-11-30 03:01:21 +03:00
|
|
|
nsresult rv;
|
2002-02-16 04:19:24 +03:00
|
|
|
|
2018-07-22 12:11:27 +03:00
|
|
|
nsCOMPtr<nsIURI> actionURI = aFormSubmission->GetActionURL();
|
2002-03-13 09:08:56 +03:00
|
|
|
if (!actionURI) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsSubmitting = false;
|
2002-03-13 09:08:56 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-02-16 04:19:24 +03:00
|
|
|
|
2005-05-07 04:16:17 +04:00
|
|
|
// If there is no link handler, then we won't actually be able to submit.
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* doc = GetComposedDoc();
|
2019-07-09 19:17:47 +03:00
|
|
|
nsCOMPtr<nsIDocShell> container = doc ? doc->GetDocShell() : nullptr;
|
|
|
|
if (!container || IsEditable()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsSubmitting = false;
|
2005-05-07 04:16:17 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-01-11 20:58:36 +03:00
|
|
|
// javascript URIs are not really submissions; they just call a function.
|
|
|
|
// Also, they may synchronously call submit(), and we want them to be able to
|
|
|
|
// do so while still disallowing other double submissions. (Bug 139798)
|
|
|
|
// Note that any other URI types that are of equivalent type should also be
|
|
|
|
// added here.
|
|
|
|
// XXXbz this is a mess. The real issue here is that nsJSChannel sets the
|
|
|
|
// LOAD_BACKGROUND flag, so doesn't notify us, compounded by the fact that
|
|
|
|
// the JS executes before we forget the submission in OnStateChange on
|
|
|
|
// STATE_STOP. As a result, we have to make sure that we simply pretend
|
|
|
|
// we're not submitting when submitting to a JS URL. That's kinda bogus, but
|
|
|
|
// there we are.
|
2019-08-02 11:54:18 +03:00
|
|
|
bool schemeIsJavaScript = actionURI->SchemeIs("javascript");
|
|
|
|
if (schemeIsJavaScript) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsSubmitting = false;
|
2007-01-11 20:58:36 +03:00
|
|
|
}
|
2002-05-01 03:21:58 +04:00
|
|
|
|
2002-03-13 09:08:56 +03:00
|
|
|
//
|
|
|
|
// Notify observers of submit
|
|
|
|
//
|
2011-09-29 10:19:26 +04:00
|
|
|
bool cancelSubmit = false;
|
2006-06-23 06:44:39 +04:00
|
|
|
if (mNotifiedObservers) {
|
|
|
|
cancelSubmit = mNotifiedObserversResult;
|
|
|
|
} else {
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = NotifySubmitObservers(actionURI, &cancelSubmit, true);
|
2006-06-23 06:44:39 +04:00
|
|
|
NS_ENSURE_SUBMIT_SUCCESS(rv);
|
|
|
|
}
|
2002-03-13 09:08:56 +03:00
|
|
|
|
2006-06-23 06:44:39 +04:00
|
|
|
if (cancelSubmit) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsSubmitting = false;
|
2002-03-13 09:08:56 +03:00
|
|
|
return NS_OK;
|
2002-02-16 04:19:24 +03:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
cancelSubmit = false;
|
|
|
|
rv = NotifySubmitObservers(actionURI, &cancelSubmit, false);
|
2006-07-18 04:18:32 +04:00
|
|
|
NS_ENSURE_SUBMIT_SUCCESS(rv);
|
|
|
|
|
|
|
|
if (cancelSubmit) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsSubmitting = false;
|
2006-07-18 04:18:32 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-03-13 09:08:56 +03:00
|
|
|
//
|
|
|
|
// Submit
|
|
|
|
//
|
|
|
|
nsCOMPtr<nsIDocShell> docShell;
|
2004-09-04 23:28:46 +04:00
|
|
|
|
|
|
|
{
|
2019-05-24 15:42:29 +03:00
|
|
|
AutoPopupStatePusher popupStatePusher(mSubmitPopupState);
|
2004-09-04 23:28:46 +04:00
|
|
|
|
2013-10-22 17:27:35 +04:00
|
|
|
AutoHandlingUserInputStatePusher userInpStatePusher(
|
2019-05-29 10:48:16 +03:00
|
|
|
aFormSubmission->IsInitiatedFromUserInput());
|
2004-09-04 23:28:46 +04:00
|
|
|
|
2010-02-25 08:58:17 +03:00
|
|
|
nsCOMPtr<nsIInputStream> postDataStream;
|
|
|
|
rv = aFormSubmission->GetEncodedSubmission(
|
2017-09-22 09:12:03 +03:00
|
|
|
actionURI, getter_AddRefs(postDataStream), actionURI);
|
2010-02-25 08:58:17 +03:00
|
|
|
NS_ENSURE_SUBMIT_SUCCESS(rv);
|
2004-09-04 23:28:46 +04:00
|
|
|
|
2018-07-22 12:11:27 +03:00
|
|
|
nsAutoString target;
|
|
|
|
aFormSubmission->GetTarget(target);
|
2019-07-09 19:17:47 +03:00
|
|
|
rv = nsDocShell::Cast(container)->OnLinkClickSync(
|
2018-05-23 08:12:36 +03:00
|
|
|
this, actionURI, target, VoidString(), postDataStream, nullptr, false,
|
2018-04-20 23:59:36 +03:00
|
|
|
getter_AddRefs(docShell), getter_AddRefs(mSubmittingRequest),
|
2019-05-14 15:41:19 +03:00
|
|
|
aFormSubmission->IsInitiatedFromUserInput());
|
2010-02-25 08:58:17 +03:00
|
|
|
NS_ENSURE_SUBMIT_SUCCESS(rv);
|
|
|
|
}
|
2002-03-13 09:08:56 +03:00
|
|
|
|
2002-03-27 08:45:17 +03:00
|
|
|
// Even if the submit succeeds, it's possible for there to be no docshell
|
|
|
|
// or request; for example, if it's to a named anchor within the same page
|
|
|
|
// the submit will not really do anything.
|
|
|
|
if (docShell) {
|
2002-08-01 22:17:48 +04:00
|
|
|
// If the channel is pending, we have to listen for web progress.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool pending = false;
|
2002-08-01 22:17:48 +04:00
|
|
|
mSubmittingRequest->IsPending(&pending);
|
2007-01-11 20:58:36 +03:00
|
|
|
if (pending && !schemeIsJavaScript) {
|
2007-11-30 20:57:03 +03:00
|
|
|
nsCOMPtr<nsIWebProgress> webProgress = do_GetInterface(docShell);
|
|
|
|
NS_ASSERTION(webProgress, "nsIDocShell not converted to nsIWebProgress!");
|
|
|
|
rv = webProgress->AddProgressListener(this,
|
|
|
|
nsIWebProgress::NOTIFY_STATE_ALL);
|
2002-08-01 22:17:48 +04:00
|
|
|
NS_ENSURE_SUBMIT_SUCCESS(rv);
|
2007-11-30 20:57:03 +03:00
|
|
|
mWebProgress = do_GetWeakReference(webProgress);
|
|
|
|
NS_ASSERTION(mWebProgress, "can't hold weak ref to webprogress!");
|
2002-08-01 22:17:48 +04:00
|
|
|
} else {
|
2002-08-20 06:35:39 +04:00
|
|
|
ForgetCurrentSubmission();
|
2002-08-01 22:17:48 +04:00
|
|
|
}
|
2002-08-20 06:35:39 +04:00
|
|
|
} else {
|
|
|
|
ForgetCurrentSubmission();
|
2002-03-27 08:45:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
2002-02-16 04:19:24 +03:00
|
|
|
}
|
|
|
|
|
2015-01-15 22:01:10 +03:00
|
|
|
nsresult HTMLFormElement::DoSecureToInsecureSubmitCheck(nsIURI* aActionURL,
|
|
|
|
bool* aCancelSubmit) {
|
|
|
|
*aCancelSubmit = false;
|
|
|
|
|
|
|
|
// Only ask the user about posting from a secure URI to an insecure URI if
|
|
|
|
// this element is in the root document. When this is not the case, the mixed
|
|
|
|
// content blocker will take care of security for us.
|
2019-07-26 19:48:31 +03:00
|
|
|
Document* parent = OwnerDoc()->GetInProcessParentDocument();
|
2015-01-15 22:01:10 +03:00
|
|
|
bool isRootDocument = (!parent || nsContentUtils::IsChromeDoc(parent));
|
|
|
|
if (!isRootDocument) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIPrincipal* principal = NodePrincipal();
|
|
|
|
if (!principal) {
|
|
|
|
*aCancelSubmit = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-09-26 13:47:16 +03:00
|
|
|
bool formIsHTTPS = principal->SchemeIs("https");
|
|
|
|
if (principal->IsSystemPrincipal() || principal->GetIsExpandedPrincipal()) {
|
|
|
|
formIsHTTPS = OwnerDoc()->GetDocumentURI()->SchemeIs("https");
|
2015-01-15 22:01:10 +03:00
|
|
|
}
|
2019-05-10 17:17:40 +03:00
|
|
|
if (!formIsHTTPS) {
|
2015-01-15 22:01:10 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-05-10 20:50:00 +03:00
|
|
|
if (nsMixedContentBlocker::IsPotentiallyTrustworthyLoopbackURL(aActionURL)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-05-10 17:17:40 +03:00
|
|
|
if (nsMixedContentBlocker::URISafeToBeLoadedInSecureContext(aActionURL)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-03-01 11:44:30 +03:00
|
|
|
if (nsMixedContentBlocker::IsPotentiallyTrustworthyOnion(aActionURL)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> window = OwnerDoc()->GetWindow();
|
2015-06-03 23:47:56 +03:00
|
|
|
if (!window) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIDocShell> docShell = window->GetDocShell();
|
|
|
|
if (!docShell) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIPrompt> prompt = do_GetInterface(docShell);
|
|
|
|
if (!prompt) {
|
2015-01-15 22:01:10 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIStringBundle> stringBundle;
|
|
|
|
nsCOMPtr<nsIStringBundleService> stringBundleService =
|
|
|
|
mozilla::services::GetStringBundleService();
|
|
|
|
if (!stringBundleService) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2019-09-26 13:47:16 +03:00
|
|
|
nsresult rv = stringBundleService->CreateBundle(
|
2015-01-15 22:01:10 +03:00
|
|
|
"chrome://global/locale/browser.properties",
|
|
|
|
getter_AddRefs(stringBundle));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
nsAutoString title;
|
|
|
|
nsAutoString message;
|
|
|
|
nsAutoString cont;
|
2017-08-04 07:40:52 +03:00
|
|
|
stringBundle->GetStringFromName("formPostSecureToInsecureWarning.title",
|
|
|
|
title);
|
|
|
|
stringBundle->GetStringFromName("formPostSecureToInsecureWarning.message",
|
|
|
|
message);
|
|
|
|
stringBundle->GetStringFromName("formPostSecureToInsecureWarning.continue",
|
|
|
|
cont);
|
2015-01-15 22:01:10 +03:00
|
|
|
int32_t buttonPressed;
|
|
|
|
bool checkState =
|
|
|
|
false; // this is unused (ConfirmEx requires this parameter)
|
2015-06-03 23:47:56 +03:00
|
|
|
rv = prompt->ConfirmEx(
|
|
|
|
title.get(), message.get(),
|
|
|
|
(nsIPrompt::BUTTON_TITLE_IS_STRING * nsIPrompt::BUTTON_POS_0) +
|
|
|
|
(nsIPrompt::BUTTON_TITLE_CANCEL * nsIPrompt::BUTTON_POS_1),
|
|
|
|
cont.get(), nullptr, nullptr, nullptr, &checkState, &buttonPressed);
|
2015-01-15 22:01:10 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
*aCancelSubmit = (buttonPressed == 1);
|
|
|
|
uint32_t telemetryBucket =
|
|
|
|
nsISecurityUITelemetry::WARNING_CONFIRM_POST_TO_INSECURE_FROM_SECURE;
|
|
|
|
mozilla::Telemetry::Accumulate(mozilla::Telemetry::SECURITY_UI,
|
|
|
|
telemetryBucket);
|
|
|
|
if (!*aCancelSubmit) {
|
|
|
|
// The user opted to continue, so note that in the next telemetry bucket.
|
|
|
|
mozilla::Telemetry::Accumulate(mozilla::Telemetry::SECURITY_UI,
|
|
|
|
telemetryBucket + 1);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
nsresult HTMLFormElement::NotifySubmitObservers(nsIURI* aActionURL,
|
|
|
|
bool* aCancelSubmit,
|
|
|
|
bool aEarlyNotify) {
|
2015-01-15 22:01:10 +03:00
|
|
|
if (!aEarlyNotify) {
|
|
|
|
nsresult rv = DoSecureToInsecureSubmitCheck(aActionURL, aCancelSubmit);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
if (*aCancelSubmit) {
|
|
|
|
return NS_OK;
|
2014-01-24 00:06:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-23 03:23:55 +03:00
|
|
|
bool defaultAction = true;
|
|
|
|
nsresult rv = nsContentUtils::DispatchEventOnlyToChrome(
|
|
|
|
OwnerDoc(), static_cast<nsINode*>(this),
|
|
|
|
aEarlyNotify ? NS_LITERAL_STRING("DOMFormBeforeSubmit")
|
|
|
|
: NS_LITERAL_STRING("DOMFormSubmit"),
|
|
|
|
CanBubble::eYes, Cancelable::eYes, &defaultAction);
|
|
|
|
*aCancelSubmit = !defaultAction;
|
|
|
|
if (*aCancelSubmit) {
|
|
|
|
return NS_OK;
|
2002-02-16 04:19:24 +03:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2019-09-09 16:53:27 +03:00
|
|
|
nsresult HTMLFormElement::ConstructEntryList(FormData* aFormData) {
|
|
|
|
MOZ_ASSERT(aFormData, "Must have FormData!");
|
2019-09-09 16:53:34 +03:00
|
|
|
bool isFormDataEventEnabled = StaticPrefs::dom_formdata_event_enabled();
|
|
|
|
if (isFormDataEventEnabled && mIsConstructingEntryList) {
|
2019-09-09 16:53:27 +03:00
|
|
|
// Step 2.2 of https://xhr.spec.whatwg.org/#dom-formdata.
|
|
|
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoRestore<bool> resetConstructingEntryList(mIsConstructingEntryList);
|
|
|
|
mIsConstructingEntryList = true;
|
2017-07-28 18:33:41 +03:00
|
|
|
// This shouldn't be called recursively, so use a rather large value
|
|
|
|
// for the preallocated buffer.
|
2017-07-28 18:38:26 +03:00
|
|
|
AutoTArray<RefPtr<nsGenericHTMLFormElement>, 100> sortedControls;
|
2006-09-18 08:53:54 +04:00
|
|
|
nsresult rv = mControls->GetSortedControls(sortedControls);
|
2002-08-17 09:42:55 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-02-16 04:19:24 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t len = sortedControls.Length();
|
2012-07-31 18:00:13 +04:00
|
|
|
|
2002-02-16 04:19:24 +03:00
|
|
|
//
|
|
|
|
// Walk the list of nodes and call SubmitNamesValues() on the controls
|
|
|
|
//
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < len; ++i) {
|
2002-02-16 04:19:24 +03:00
|
|
|
// Tell the control to submit its name/value pairs to the submission
|
2019-09-09 16:53:27 +03:00
|
|
|
sortedControls[i]->SubmitNamesValues(aFormData);
|
2019-09-06 23:50:52 +03:00
|
|
|
}
|
2019-09-06 23:50:50 +03:00
|
|
|
|
2019-09-09 16:53:34 +03:00
|
|
|
if (isFormDataEventEnabled) {
|
|
|
|
FormDataEventInit init;
|
|
|
|
init.mBubbles = true;
|
|
|
|
init.mCancelable = false;
|
|
|
|
init.mFormData = aFormData;
|
|
|
|
RefPtr<FormDataEvent> event =
|
|
|
|
FormDataEvent::Constructor(this, NS_LITERAL_STRING("formdata"), init);
|
|
|
|
event->SetTrusted(true);
|
2019-09-09 16:53:27 +03:00
|
|
|
|
2019-09-09 16:53:34 +03:00
|
|
|
EventDispatcher::DispatchDOMEvent(ToSupports(this), nullptr, event, nullptr,
|
|
|
|
nullptr);
|
|
|
|
}
|
2019-09-09 16:53:27 +03:00
|
|
|
|
2002-02-16 04:19:24 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-09-09 16:53:27 +03:00
|
|
|
NotNull<const Encoding*> HTMLFormElement::GetSubmitEncoding() {
|
|
|
|
nsAutoString acceptCharsetValue;
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::acceptcharset, acceptCharsetValue);
|
|
|
|
|
|
|
|
int32_t charsetLen = acceptCharsetValue.Length();
|
|
|
|
if (charsetLen > 0) {
|
|
|
|
int32_t offset = 0;
|
|
|
|
int32_t spPos = 0;
|
|
|
|
// get charset from charsets one by one
|
|
|
|
do {
|
|
|
|
spPos = acceptCharsetValue.FindChar(char16_t(' '), offset);
|
|
|
|
int32_t cnt = ((-1 == spPos) ? (charsetLen - offset) : (spPos - offset));
|
|
|
|
if (cnt > 0) {
|
|
|
|
nsAutoString uCharset;
|
|
|
|
acceptCharsetValue.Mid(uCharset, offset, cnt);
|
|
|
|
|
|
|
|
auto encoding = Encoding::ForLabelNoReplacement(uCharset);
|
|
|
|
if (encoding) {
|
|
|
|
return WrapNotNull(encoding);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
offset = spPos + 1;
|
|
|
|
} while (spPos != -1);
|
|
|
|
}
|
|
|
|
// if there are no accept-charset or all the charset are not supported
|
|
|
|
// Get the charset from document
|
|
|
|
Document* doc = GetComposedDoc();
|
|
|
|
if (doc) {
|
|
|
|
return doc->GetDocumentCharacterSet();
|
|
|
|
}
|
|
|
|
return UTF_8_ENCODING;
|
|
|
|
}
|
|
|
|
|
1998-09-23 21:16:51 +04:00
|
|
|
// nsIForm
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_IMETHODIMP_(uint32_t)
|
2016-04-12 14:02:42 +03:00
|
|
|
HTMLFormElement::GetElementCount() const { return mControls->Length(); }
|
1998-09-23 21:16:51 +04:00
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
Element* HTMLFormElement::IndexedGetter(uint32_t aIndex, bool& aFound) {
|
|
|
|
Element* element = mControls->mElements.SafeElementAt(aIndex, nullptr);
|
|
|
|
aFound = element != nullptr;
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
2009-10-30 04:49:11 +03:00
|
|
|
NS_IMETHODIMP_(nsIFormControl*)
|
2013-06-19 18:24:37 +04:00
|
|
|
HTMLFormElement::GetElementAt(int32_t aIndex) const {
|
2012-07-30 18:20:58 +04:00
|
|
|
return mControls->mElements.SafeElementAt(aIndex, nullptr);
|
1998-09-23 21:16:51 +04:00
|
|
|
}
|
|
|
|
|
2007-07-26 08:26:07 +04:00
|
|
|
/**
|
|
|
|
* Compares the position of aControl1 and aControl2 in the document
|
|
|
|
* @param aControl1 First control to compare.
|
|
|
|
* @param aControl2 Second control to compare.
|
|
|
|
* @param aForm Parent form of the controls.
|
|
|
|
* @return < 0 if aControl1 is before aControl2,
|
|
|
|
* > 0 if aControl1 is after aControl2,
|
|
|
|
* 0 otherwise
|
|
|
|
*/
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
int32_t HTMLFormElement::CompareFormControlPosition(Element* aElement1,
|
|
|
|
Element* aElement2,
|
|
|
|
const nsIContent* aForm) {
|
2013-06-18 16:53:23 +04:00
|
|
|
NS_ASSERTION(aElement1 != aElement2, "Comparing a form control to itself");
|
2007-07-26 08:26:07 +04:00
|
|
|
|
2012-03-27 04:52:39 +04:00
|
|
|
// If an element has a @form, we can assume it *might* be able to not have
|
|
|
|
// a parent and still be in the form.
|
2013-06-18 16:53:23 +04:00
|
|
|
NS_ASSERTION((aElement1->HasAttr(kNameSpaceID_None, nsGkAtoms::form) ||
|
|
|
|
aElement1->GetParent()) &&
|
|
|
|
(aElement2->HasAttr(kNameSpaceID_None, nsGkAtoms::form) ||
|
|
|
|
aElement2->GetParent()),
|
2007-07-26 08:26:07 +04:00
|
|
|
"Form controls should always have parents");
|
2010-08-24 05:11:04 +04:00
|
|
|
|
|
|
|
// If we pass aForm, we are assuming both controls are form descendants which
|
|
|
|
// is not always the case. This function should work but maybe slower.
|
|
|
|
// However, checking if both elements are form descendants may be slow too...
|
2010-10-13 14:52:45 +04:00
|
|
|
// TODO: remove the prevent asserts fix, see bug 598468.
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsLayoutUtils::gPreventAssertInCompareTreePosition = true;
|
2013-06-18 16:53:23 +04:00
|
|
|
int32_t rVal =
|
|
|
|
nsLayoutUtils::CompareTreePosition(aElement1, aElement2, aForm);
|
2010-10-13 14:52:45 +04:00
|
|
|
nsLayoutUtils::gPreventAssertInCompareTreePosition = false;
|
|
|
|
|
|
|
|
return rVal;
|
|
|
|
#else // DEBUG
|
2013-06-18 16:53:23 +04:00
|
|
|
return nsLayoutUtils::CompareTreePosition(aElement1, aElement2, aForm);
|
2010-10-13 14:52:45 +04:00
|
|
|
#endif // DEBUG
|
2007-07-26 08:26:07 +04:00
|
|
|
}
|
2013-06-18 16:53:23 +04:00
|
|
|
|
2007-07-26 08:26:07 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
/**
|
|
|
|
* Checks that all form elements are in document order. Asserts if any pair of
|
|
|
|
* consecutive elements are not in increasing document order.
|
|
|
|
*
|
|
|
|
* @param aControls List of form controls to check.
|
|
|
|
* @param aForm Parent form of the controls.
|
|
|
|
*/
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
void HTMLFormElement::AssertDocumentOrder(
|
2013-10-03 11:11:26 +04:00
|
|
|
const nsTArray<nsGenericHTMLFormElement*>& aControls, nsIContent* aForm) {
|
2010-10-13 14:52:45 +04:00
|
|
|
// TODO: remove the return statement with bug 598468.
|
|
|
|
// This is done to prevent asserts in some edge cases.
|
|
|
|
return;
|
|
|
|
|
2007-07-26 08:26:07 +04:00
|
|
|
// Only iterate if aControls is not empty, since otherwise
|
|
|
|
// |aControls.Length() - 1| will be a very large unsigned number... not what
|
|
|
|
// we want here.
|
|
|
|
if (!aControls.IsEmpty()) {
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < aControls.Length() - 1; ++i) {
|
2007-07-26 08:26:07 +04:00
|
|
|
NS_ASSERTION(
|
|
|
|
CompareFormControlPosition(aControls[i], aControls[i + 1], aForm) < 0,
|
|
|
|
"Form controls not ordered correctly");
|
|
|
|
}
|
|
|
|
}
|
2004-10-31 22:58:10 +03:00
|
|
|
}
|
2017-07-28 18:38:26 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy of the above function, but with RefPtrs.
|
|
|
|
*
|
|
|
|
* @param aControls List of form controls to check.
|
|
|
|
* @param aForm Parent form of the controls.
|
|
|
|
*/
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
void HTMLFormElement::AssertDocumentOrder(
|
2017-07-28 18:38:26 +03:00
|
|
|
const nsTArray<RefPtr<nsGenericHTMLFormElement>>& aControls,
|
|
|
|
nsIContent* aForm) {
|
|
|
|
// TODO: remove the return statement with bug 598468.
|
|
|
|
// This is done to prevent asserts in some edge cases.
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Only iterate if aControls is not empty, since otherwise
|
|
|
|
// |aControls.Length() - 1| will be a very large unsigned number... not what
|
|
|
|
// we want here.
|
|
|
|
if (!aControls.IsEmpty()) {
|
|
|
|
for (uint32_t i = 0; i < aControls.Length() - 1; ++i) {
|
|
|
|
NS_ASSERTION(
|
|
|
|
CompareFormControlPosition(aControls[i], aControls[i + 1], aForm) < 0,
|
|
|
|
"Form controls not ordered correctly");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-07-26 08:26:07 +04:00
|
|
|
#endif
|
2004-10-31 22:58:10 +03:00
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
void HTMLFormElement::PostPasswordEvent() {
|
2013-01-31 22:47:00 +04:00
|
|
|
// Don't fire another add event if we have a pending add event.
|
2014-03-17 10:56:54 +04:00
|
|
|
if (mFormPasswordEventDispatcher.get()) {
|
2013-01-31 22:47:00 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-17 10:56:54 +04:00
|
|
|
mFormPasswordEventDispatcher =
|
2018-06-25 19:23:50 +03:00
|
|
|
new AsyncEventDispatcher(this, NS_LITERAL_STRING("DOMFormHasPassword"),
|
|
|
|
CanBubble::eYes, ChromeOnlyDispatch::eYes);
|
2014-03-17 10:56:54 +04:00
|
|
|
mFormPasswordEventDispatcher->PostDOMEvent();
|
2013-01-31 22:47:00 +04:00
|
|
|
}
|
|
|
|
|
2014-09-17 17:46:24 +04:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct FormComparator {
|
|
|
|
Element* const mChild;
|
|
|
|
HTMLFormElement* const mForm;
|
|
|
|
FormComparator(Element* aChild, HTMLFormElement* aForm)
|
|
|
|
: mChild(aChild), mForm(aForm) {}
|
|
|
|
int operator()(Element* aElement) const {
|
|
|
|
return HTMLFormElement::CompareFormControlPosition(mChild, aElement, mForm);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2013-06-18 16:53:23 +04:00
|
|
|
// This function return true if the element, once appended, is the last one in
|
|
|
|
// the array.
|
|
|
|
template <typename ElementType>
|
|
|
|
static bool AddElementToList(nsTArray<ElementType*>& aList, ElementType* aChild,
|
2013-06-19 18:24:37 +04:00
|
|
|
HTMLFormElement* aForm) {
|
2013-06-18 16:53:23 +04:00
|
|
|
NS_ASSERTION(aList.IndexOf(aChild) == aList.NoIndex,
|
|
|
|
"aChild already in aList");
|
2007-07-26 08:26:07 +04:00
|
|
|
|
2014-09-17 17:46:24 +04:00
|
|
|
const uint32_t count = aList.Length();
|
2013-06-18 16:53:23 +04:00
|
|
|
ElementType* element;
|
|
|
|
bool lastElement = false;
|
2007-07-26 08:26:07 +04:00
|
|
|
|
2006-09-18 08:53:54 +04:00
|
|
|
// Optimize most common case where we insert at the end.
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t position = -1;
|
2006-09-18 08:53:54 +04:00
|
|
|
if (count > 0) {
|
2013-06-18 16:53:23 +04:00
|
|
|
element = aList[count - 1];
|
2013-10-03 11:11:26 +04:00
|
|
|
position =
|
|
|
|
HTMLFormElement::CompareFormControlPosition(aChild, element, aForm);
|
2006-09-18 08:53:54 +04:00
|
|
|
}
|
2004-10-31 22:58:10 +03:00
|
|
|
|
2006-09-18 08:53:54 +04:00
|
|
|
// If this item comes after the last element, or the elements array is
|
|
|
|
// empty, we append to the end. Otherwise, we do a binary search to
|
|
|
|
// determine where the element should go.
|
|
|
|
if (position >= 0 || count == 0) {
|
|
|
|
// WEAK - don't addref
|
2013-06-18 16:53:23 +04:00
|
|
|
aList.AppendElement(aChild);
|
2011-10-17 18:59:28 +04:00
|
|
|
lastElement = true;
|
2006-09-18 08:53:54 +04:00
|
|
|
} else {
|
2014-09-17 17:46:24 +04:00
|
|
|
size_t idx;
|
|
|
|
BinarySearchIf(aList, 0, count, FormComparator(aChild, aForm), &idx);
|
2013-06-18 16:53:23 +04:00
|
|
|
|
2002-08-17 09:42:55 +04:00
|
|
|
// WEAK - don't addref
|
2014-09-17 17:46:24 +04:00
|
|
|
aList.InsertElementAt(idx, aChild);
|
2001-03-22 11:51:52 +03:00
|
|
|
}
|
|
|
|
|
2013-06-18 16:53:23 +04:00
|
|
|
return lastElement;
|
|
|
|
}
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
nsresult HTMLFormElement::AddElement(nsGenericHTMLFormElement* aChild,
|
|
|
|
bool aUpdateValidity, bool aNotify) {
|
2013-06-18 16:53:23 +04:00
|
|
|
// If an element has a @form, we can assume it *might* be able to not have
|
|
|
|
// a parent and still be in the form.
|
|
|
|
NS_ASSERTION(aChild->HasAttr(kNameSpaceID_None, nsGkAtoms::form) ||
|
|
|
|
aChild->GetParent(),
|
|
|
|
"Form control should have a parent");
|
|
|
|
|
|
|
|
// Determine whether to add the new element to the elements or
|
|
|
|
// the not-in-elements list.
|
2013-10-03 11:11:26 +04:00
|
|
|
bool childInElements = HTMLFormControlsCollection::ShouldBeInElements(aChild);
|
2013-06-18 16:53:23 +04:00
|
|
|
nsTArray<nsGenericHTMLFormElement*>& controlList =
|
|
|
|
childInElements ? mControls->mElements : mControls->mNotInElements;
|
|
|
|
|
|
|
|
bool lastElement = AddElementToList(controlList, aChild, this);
|
|
|
|
|
2007-07-26 08:26:07 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
AssertDocumentOrder(controlList, this);
|
|
|
|
#endif
|
2011-02-25 21:16:04 +03:00
|
|
|
|
2017-04-01 05:49:00 +03:00
|
|
|
int32_t type = aChild->ControlType();
|
2002-03-07 23:53:40 +03:00
|
|
|
|
2019-02-23 03:23:14 +03:00
|
|
|
// If it is a password control, inform the password manager.
|
2013-01-31 22:47:00 +04:00
|
|
|
if (type == NS_FORM_INPUT_PASSWORD) {
|
|
|
|
PostPasswordEvent();
|
2002-06-04 04:44:04 +04:00
|
|
|
}
|
2016-04-12 14:02:42 +03:00
|
|
|
|
2006-08-16 07:20:19 +04:00
|
|
|
// Default submit element handling
|
|
|
|
if (aChild->IsSubmitControl()) {
|
2007-08-07 06:07:24 +04:00
|
|
|
// Update mDefaultSubmitElement, mFirstSubmitInElements,
|
|
|
|
// mFirstSubmitNotInElements.
|
|
|
|
|
2009-10-30 04:49:11 +03:00
|
|
|
nsGenericHTMLFormElement** firstSubmitSlot =
|
2007-08-07 06:07:24 +04:00
|
|
|
childInElements ? &mFirstSubmitInElements : &mFirstSubmitNotInElements;
|
2016-04-12 14:02:42 +03:00
|
|
|
|
2007-08-07 06:07:24 +04:00
|
|
|
// The new child is the new first submit in its list if the firstSubmitSlot
|
|
|
|
// is currently empty or if the child is before what's currently in the
|
|
|
|
// slot. Note that if we already have a control in firstSubmitSlot and
|
|
|
|
// we're appending this element can't possibly replace what's currently in
|
|
|
|
// the slot. Also note that aChild can't become the mDefaultSubmitElement
|
|
|
|
// unless it replaces what's in the slot. If it _does_ replace what's in
|
|
|
|
// the slot, it becomes the default submit if either the default submit is
|
|
|
|
// what's in the slot or the child is earlier than the default submit.
|
2011-06-01 05:46:57 +04:00
|
|
|
nsGenericHTMLFormElement* oldDefaultSubmit = mDefaultSubmitElement;
|
2007-08-07 06:07:24 +04:00
|
|
|
if (!*firstSubmitSlot ||
|
|
|
|
(!lastElement &&
|
|
|
|
CompareFormControlPosition(aChild, *firstSubmitSlot, this) < 0)) {
|
2009-09-18 22:52:36 +04:00
|
|
|
// Update mDefaultSubmitElement if it's currently in a valid state.
|
|
|
|
// Valid state means either non-null or null because there are in fact
|
|
|
|
// no submit elements around.
|
|
|
|
if ((mDefaultSubmitElement ||
|
|
|
|
(!mFirstSubmitInElements && !mFirstSubmitNotInElements)) &&
|
|
|
|
(*firstSubmitSlot == mDefaultSubmitElement ||
|
|
|
|
CompareFormControlPosition(aChild, mDefaultSubmitElement, this) <
|
|
|
|
0)) {
|
2007-08-07 06:07:24 +04:00
|
|
|
mDefaultSubmitElement = aChild;
|
|
|
|
}
|
|
|
|
*firstSubmitSlot = aChild;
|
2006-08-16 07:20:19 +04:00
|
|
|
}
|
2017-11-05 08:48:48 +03:00
|
|
|
|
|
|
|
MOZ_ASSERT(mDefaultSubmitElement == mFirstSubmitInElements ||
|
|
|
|
mDefaultSubmitElement == mFirstSubmitNotInElements ||
|
|
|
|
!mDefaultSubmitElement,
|
|
|
|
"What happened here?");
|
2006-08-16 07:20:19 +04:00
|
|
|
|
2007-02-09 09:20:47 +03:00
|
|
|
// Notify that the state of the previous default submit element has changed
|
|
|
|
// if the element which is the default submit element has changed. The new
|
2011-06-01 05:46:57 +04:00
|
|
|
// default submit element is responsible for its own state update.
|
|
|
|
if (oldDefaultSubmit && oldDefaultSubmit != mDefaultSubmitElement) {
|
|
|
|
oldDefaultSubmit->UpdateState(aNotify);
|
2006-08-16 07:20:19 +04:00
|
|
|
}
|
|
|
|
}
|
2002-06-04 04:44:04 +04:00
|
|
|
|
2010-09-10 09:08:56 +04:00
|
|
|
// If the element is subject to constraint validaton and is invalid, we need
|
|
|
|
// to update our internal counter.
|
2010-10-08 17:42:09 +04:00
|
|
|
if (aUpdateValidity) {
|
2011-08-31 01:45:31 +04:00
|
|
|
nsCOMPtr<nsIConstraintValidation> cvElmt = do_QueryObject(aChild);
|
2010-10-08 17:42:09 +04:00
|
|
|
if (cvElmt && cvElmt->IsCandidateForConstraintValidation() &&
|
|
|
|
!cvElmt->IsValid()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
UpdateValidity(false);
|
2010-10-08 17:42:09 +04:00
|
|
|
}
|
2010-09-10 09:08:56 +04:00
|
|
|
}
|
|
|
|
|
2011-02-25 21:16:04 +03:00
|
|
|
// Notify the radio button it's been added to a group
|
|
|
|
// This has to be done _after_ UpdateValidity() call to prevent the element
|
|
|
|
// being count twice.
|
|
|
|
if (type == NS_FORM_INPUT_RADIO) {
|
2013-03-28 23:41:32 +04:00
|
|
|
RefPtr<HTMLInputElement> radio = static_cast<HTMLInputElement*>(aChild);
|
2011-02-25 21:16:04 +03:00
|
|
|
radio->AddedToRadioGroup();
|
|
|
|
}
|
|
|
|
|
2001-03-22 11:51:52 +03:00
|
|
|
return NS_OK;
|
1998-09-23 21:16:51 +04:00
|
|
|
}
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
nsresult HTMLFormElement::AddElementToTable(nsGenericHTMLFormElement* aChild,
|
|
|
|
const nsAString& aName) {
|
2016-04-12 14:02:42 +03:00
|
|
|
return mControls->AddElementToTable(aChild, aName);
|
2000-04-19 11:49:07 +04:00
|
|
|
}
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
nsresult HTMLFormElement::RemoveElement(nsGenericHTMLFormElement* aChild,
|
|
|
|
bool aUpdateValidity) {
|
2016-11-21 20:34:02 +03:00
|
|
|
RemoveElementFromPastNamesMap(aChild);
|
|
|
|
|
2002-03-07 23:53:40 +03:00
|
|
|
//
|
|
|
|
// Remove it from the radio group if it's a radio button
|
|
|
|
//
|
2006-08-16 07:20:19 +04:00
|
|
|
nsresult rv = NS_OK;
|
2017-04-01 05:49:00 +03:00
|
|
|
if (aChild->ControlType() == NS_FORM_INPUT_RADIO) {
|
2013-03-28 23:41:32 +04:00
|
|
|
RefPtr<HTMLInputElement> radio = static_cast<HTMLInputElement*>(aChild);
|
2010-11-11 15:34:27 +03:00
|
|
|
radio->WillRemoveFromRadioGroup();
|
2002-03-07 23:53:40 +03:00
|
|
|
}
|
|
|
|
|
2006-09-18 08:53:54 +04:00
|
|
|
// Determine whether to remove the child from the elements list
|
|
|
|
// or the not in elements list.
|
2013-10-03 11:11:26 +04:00
|
|
|
bool childInElements = HTMLFormControlsCollection::ShouldBeInElements(aChild);
|
2009-10-30 04:49:11 +03:00
|
|
|
nsTArray<nsGenericHTMLFormElement*>& controls =
|
2006-09-18 08:53:54 +04:00
|
|
|
childInElements ? mControls->mElements : mControls->mNotInElements;
|
2016-04-12 14:02:42 +03:00
|
|
|
|
2006-09-18 08:53:54 +04:00
|
|
|
// Find the index of the child. This will be used later if necessary
|
|
|
|
// to find the default submit.
|
2014-05-09 05:03:35 +04:00
|
|
|
size_t index = controls.IndexOf(aChild);
|
2008-12-03 13:38:15 +03:00
|
|
|
NS_ENSURE_STATE(index != controls.NoIndex);
|
2006-09-18 08:53:54 +04:00
|
|
|
|
|
|
|
controls.RemoveElementAt(index);
|
2002-07-21 03:09:24 +04:00
|
|
|
|
2007-08-07 06:07:24 +04:00
|
|
|
// Update our mFirstSubmit* values.
|
2009-10-30 04:49:11 +03:00
|
|
|
nsGenericHTMLFormElement** firstSubmitSlot =
|
2007-08-07 06:07:24 +04:00
|
|
|
childInElements ? &mFirstSubmitInElements : &mFirstSubmitNotInElements;
|
|
|
|
if (aChild == *firstSubmitSlot) {
|
2012-07-30 18:20:58 +04:00
|
|
|
*firstSubmitSlot = nullptr;
|
2007-08-07 06:07:24 +04:00
|
|
|
|
|
|
|
// We are removing the first submit in this list, find the new first submit
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t length = controls.Length();
|
|
|
|
for (uint32_t i = index; i < length; ++i) {
|
2009-10-30 04:49:11 +03:00
|
|
|
nsGenericHTMLFormElement* currentControl = controls[i];
|
2007-08-07 06:07:24 +04:00
|
|
|
if (currentControl->IsSubmitControl()) {
|
|
|
|
*firstSubmitSlot = currentControl;
|
|
|
|
break;
|
|
|
|
}
|
2006-08-16 07:20:19 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-07 06:07:24 +04:00
|
|
|
if (aChild == mDefaultSubmitElement) {
|
2009-09-09 00:00:20 +04:00
|
|
|
// Need to reset mDefaultSubmitElement. Do this asynchronously so
|
|
|
|
// that we're not doing it while the DOM is in flux.
|
2012-07-30 18:20:58 +04:00
|
|
|
mDefaultSubmitElement = nullptr;
|
2010-11-11 15:36:42 +03:00
|
|
|
nsContentUtils::AddScriptRunner(new RemoveElementRunnable(this));
|
2009-09-09 00:00:20 +04:00
|
|
|
|
|
|
|
// Note that we don't need to notify on the old default submit (which is
|
|
|
|
// being removed) because it's either being removed from the DOM or
|
|
|
|
// changing attributes in a way that makes it responsible for sending its
|
|
|
|
// own notifications.
|
|
|
|
}
|
2006-09-18 08:53:54 +04:00
|
|
|
|
2010-09-10 09:08:56 +04:00
|
|
|
// If the element was subject to constraint validaton and is invalid, we need
|
|
|
|
// to update our internal counter.
|
2010-10-08 17:42:09 +04:00
|
|
|
if (aUpdateValidity) {
|
2011-08-31 01:45:31 +04:00
|
|
|
nsCOMPtr<nsIConstraintValidation> cvElmt = do_QueryObject(aChild);
|
2010-10-08 17:42:09 +04:00
|
|
|
if (cvElmt && cvElmt->IsCandidateForConstraintValidation() &&
|
|
|
|
!cvElmt->IsValid()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
UpdateValidity(true);
|
2010-10-08 17:42:09 +04:00
|
|
|
}
|
2010-09-10 09:08:56 +04:00
|
|
|
}
|
|
|
|
|
2009-09-09 00:00:20 +04:00
|
|
|
return rv;
|
|
|
|
}
|
2007-08-07 06:07:24 +04:00
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
void HTMLFormElement::HandleDefaultSubmitRemoval() {
|
2009-09-09 00:00:20 +04:00
|
|
|
if (mDefaultSubmitElement) {
|
|
|
|
// Already got reset somehow; nothing else to do here
|
|
|
|
return;
|
2006-09-18 08:53:54 +04:00
|
|
|
}
|
2007-08-07 06:07:24 +04:00
|
|
|
|
2009-09-09 00:00:20 +04:00
|
|
|
if (!mFirstSubmitNotInElements) {
|
|
|
|
mDefaultSubmitElement = mFirstSubmitInElements;
|
|
|
|
} else if (!mFirstSubmitInElements) {
|
|
|
|
mDefaultSubmitElement = mFirstSubmitNotInElements;
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(mFirstSubmitInElements != mFirstSubmitNotInElements,
|
|
|
|
"How did that happen?");
|
|
|
|
// Have both; use the earlier one
|
|
|
|
mDefaultSubmitElement =
|
|
|
|
CompareFormControlPosition(mFirstSubmitInElements,
|
|
|
|
mFirstSubmitNotInElements, this) < 0
|
|
|
|
? mFirstSubmitInElements
|
|
|
|
: mFirstSubmitNotInElements;
|
|
|
|
}
|
|
|
|
|
2017-11-05 08:48:48 +03:00
|
|
|
MOZ_ASSERT(mDefaultSubmitElement == mFirstSubmitInElements ||
|
|
|
|
mDefaultSubmitElement == mFirstSubmitNotInElements,
|
|
|
|
"What happened here?");
|
2009-09-09 00:00:20 +04:00
|
|
|
|
|
|
|
// Notify about change if needed.
|
2010-11-11 15:36:42 +03:00
|
|
|
if (mDefaultSubmitElement) {
|
2011-06-01 05:46:57 +04:00
|
|
|
mDefaultSubmitElement->UpdateState(true);
|
2009-09-09 00:00:20 +04:00
|
|
|
}
|
2006-09-18 08:53:54 +04:00
|
|
|
}
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
nsresult HTMLFormElement::RemoveElementFromTableInternal(
|
2013-06-18 16:53:23 +04:00
|
|
|
nsInterfaceHashtable<nsStringHashKey, nsISupports>& aTable,
|
|
|
|
nsIContent* aChild, const nsAString& aName) {
|
2017-06-29 21:53:46 +03:00
|
|
|
auto entry = aTable.Lookup(aName);
|
|
|
|
if (!entry) {
|
2013-06-18 16:53:23 +04:00
|
|
|
return NS_OK;
|
2017-06-29 21:53:46 +03:00
|
|
|
}
|
2013-06-18 16:54:27 +04:00
|
|
|
// Single element in the hash, just remove it if it's the one
|
|
|
|
// we're trying to remove...
|
2017-06-29 21:53:46 +03:00
|
|
|
if (entry.Data() == aChild) {
|
|
|
|
entry.Remove();
|
2013-06-19 18:24:37 +04:00
|
|
|
++mExpandoAndGeneration.generation;
|
2013-06-18 16:54:27 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-06-18 16:53:23 +04:00
|
|
|
|
2017-06-29 21:53:46 +03:00
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(entry.Data()));
|
2013-06-18 16:53:23 +04:00
|
|
|
if (content) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-06-29 21:53:46 +03:00
|
|
|
// If it's not a content node then it must be a RadioNodeList.
|
|
|
|
MOZ_ASSERT(nsCOMPtr<RadioNodeList>(do_QueryInterface(entry.Data())));
|
|
|
|
auto* list = static_cast<RadioNodeList*>(entry.Data().get());
|
2013-06-18 16:53:23 +04:00
|
|
|
|
|
|
|
list->RemoveElement(aChild);
|
|
|
|
|
2018-03-20 21:02:08 +03:00
|
|
|
uint32_t length = list->Length();
|
2013-06-18 16:53:23 +04:00
|
|
|
|
|
|
|
if (!length) {
|
|
|
|
// If the list is empty we remove if from our hash, this shouldn't
|
|
|
|
// happen tho
|
2017-06-29 21:53:46 +03:00
|
|
|
entry.Remove();
|
2013-06-19 18:24:37 +04:00
|
|
|
++mExpandoAndGeneration.generation;
|
2013-06-18 16:53:23 +04:00
|
|
|
} else if (length == 1) {
|
|
|
|
// Only one element left, replace the list in the hash with the
|
|
|
|
// single element.
|
|
|
|
nsIContent* node = list->Item(0);
|
|
|
|
if (node) {
|
2017-06-29 21:53:46 +03:00
|
|
|
entry.Data() = node;
|
2013-06-18 16:53:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
nsresult HTMLFormElement::RemoveElementFromTable(
|
|
|
|
nsGenericHTMLFormElement* aElement, const nsAString& aName) {
|
2000-06-23 18:12:24 +04:00
|
|
|
return mControls->RemoveElementFromTable(aElement, aName);
|
1998-09-23 21:16:51 +04:00
|
|
|
}
|
|
|
|
|
2013-04-04 11:03:12 +04:00
|
|
|
already_AddRefed<nsISupports> HTMLFormElement::NamedGetter(
|
2013-06-19 18:24:37 +04:00
|
|
|
const nsAString& aName, bool& aFound) {
|
|
|
|
aFound = true;
|
|
|
|
|
2013-04-04 11:03:12 +04:00
|
|
|
nsCOMPtr<nsISupports> result = DoResolveName(aName, true);
|
|
|
|
if (result) {
|
2013-06-18 16:54:27 +04:00
|
|
|
AddToPastNamesMap(aName, result);
|
2013-04-04 11:03:12 +04:00
|
|
|
return result.forget();
|
|
|
|
}
|
|
|
|
|
2013-06-18 16:53:23 +04:00
|
|
|
result = mImageNameLookupTable.GetWeak(aName);
|
2013-06-18 16:54:27 +04:00
|
|
|
if (result) {
|
|
|
|
AddToPastNamesMap(aName, result);
|
|
|
|
return result.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
result = mPastNameLookupTable.GetWeak(aName);
|
2013-06-19 18:24:37 +04:00
|
|
|
if (result) {
|
|
|
|
return result.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
aFound = false;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-05-10 05:25:40 +03:00
|
|
|
void HTMLFormElement::GetSupportedNames(nsTArray<nsString>& aRetval) {
|
2016-08-31 17:57:40 +03:00
|
|
|
// TODO https://github.com/whatwg/html/issues/1731
|
2013-06-19 18:24:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsISupports> HTMLFormElement::FindNamedItem(
|
|
|
|
const nsAString& aName, nsWrapperCache** aCache) {
|
|
|
|
// FIXME Get the wrapper cache from DoResolveName.
|
|
|
|
|
|
|
|
bool found;
|
|
|
|
nsCOMPtr<nsISupports> result = NamedGetter(aName, found);
|
2013-06-18 16:53:23 +04:00
|
|
|
if (result) {
|
2013-04-04 11:03:12 +04:00
|
|
|
*aCache = nullptr;
|
2013-06-18 16:53:23 +04:00
|
|
|
return result.forget();
|
2013-04-04 11:03:12 +04:00
|
|
|
}
|
|
|
|
|
2013-06-18 16:53:23 +04:00
|
|
|
return nullptr;
|
2006-02-08 08:56:13 +03:00
|
|
|
}
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
already_AddRefed<nsISupports> HTMLFormElement::DoResolveName(
|
|
|
|
const nsAString& aName, bool aFlushContent) {
|
2013-04-22 15:15:59 +04:00
|
|
|
nsCOMPtr<nsISupports> result =
|
|
|
|
mControls->NamedItemInternal(aName, aFlushContent);
|
|
|
|
return result.forget();
|
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
|
|
|
}
|
|
|
|
|
2017-12-07 21:13:50 +03:00
|
|
|
void HTMLFormElement::OnSubmitClickBegin(Element* aOriginatingElement) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mDeferSubmission = true;
|
2006-06-23 06:44:39 +04:00
|
|
|
|
|
|
|
// Prepare to run NotifySubmitObservers early before the
|
|
|
|
// scripts on the page get to modify the form data, possibly
|
|
|
|
// throwing off any password manager. (bug 257781)
|
|
|
|
nsCOMPtr<nsIURI> actionURI;
|
|
|
|
nsresult rv;
|
|
|
|
|
2010-08-20 03:23:59 +04:00
|
|
|
rv = GetActionURL(getter_AddRefs(actionURI), aOriginatingElement);
|
2006-06-23 06:44:39 +04:00
|
|
|
if (NS_FAILED(rv) || !actionURI) return;
|
|
|
|
|
2010-12-16 23:13:02 +03:00
|
|
|
// Notify observers of submit if the form is valid.
|
|
|
|
// TODO: checking for mInvalidElementsCount is a temporary fix that should be
|
|
|
|
// removed with bug 610402.
|
|
|
|
if (mInvalidElementsCount == 0) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool cancelSubmit = false;
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = NotifySubmitObservers(actionURI, &cancelSubmit, true);
|
2010-12-16 23:13:02 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mNotifiedObservers = true;
|
2010-12-16 23:13:02 +03:00
|
|
|
mNotifiedObserversResult = cancelSubmit;
|
|
|
|
}
|
2006-06-23 06:44:39 +04:00
|
|
|
}
|
2002-11-30 03:01:21 +03:00
|
|
|
}
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
void HTMLFormElement::OnSubmitClickEnd() { mDeferSubmission = false; }
|
2002-11-30 03:01:21 +03:00
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
void HTMLFormElement::FlushPendingSubmission() {
|
2010-02-25 08:58:17 +03:00
|
|
|
if (mPendingSubmission) {
|
|
|
|
// Transfer owning reference so that the submissioin doesn't get deleted
|
|
|
|
// if we reenter
|
2018-05-30 22:15:35 +03:00
|
|
|
nsAutoPtr<HTMLFormSubmission> submission = std::move(mPendingSubmission);
|
2004-09-10 12:07:04 +04:00
|
|
|
|
2010-02-25 08:58:17 +03:00
|
|
|
SubmitSubmission(submission);
|
2002-11-30 03:01:21 +03:00
|
|
|
}
|
|
|
|
}
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
|
2017-07-17 09:17:19 +03:00
|
|
|
void HTMLFormElement::GetAction(nsString& aValue) {
|
|
|
|
if (!GetAttr(kNameSpaceID_None, nsGkAtoms::action, aValue) ||
|
|
|
|
aValue.IsEmpty()) {
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* document = OwnerDoc();
|
2017-07-17 09:17:19 +03:00
|
|
|
nsIURI* docURI = document->GetDocumentURI();
|
|
|
|
if (docURI) {
|
|
|
|
nsAutoCString spec;
|
|
|
|
nsresult rv = docURI->GetSpec(spec);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CopyUTF8toUTF16(spec, aValue);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
GetURIAttr(nsGkAtoms::action, nullptr, aValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
nsresult HTMLFormElement::GetActionURL(nsIURI** aActionURL,
|
2017-12-07 21:13:50 +03:00
|
|
|
Element* aOriginatingElement) {
|
2003-03-07 02:03:49 +03:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
*aActionURL = nullptr;
|
2003-03-07 02:03:49 +03:00
|
|
|
|
|
|
|
//
|
|
|
|
// Grab the URL string
|
|
|
|
//
|
2010-08-20 03:23:59 +04:00
|
|
|
// If the originating element is a submit control and has the formaction
|
|
|
|
// attribute specified, it should be used. Otherwise, the action attribute
|
|
|
|
// from the form element should be used.
|
|
|
|
//
|
2003-03-07 02:03:49 +03:00
|
|
|
nsAutoString action;
|
2010-10-29 23:49:42 +04:00
|
|
|
|
|
|
|
if (aOriginatingElement &&
|
|
|
|
aOriginatingElement->HasAttr(kNameSpaceID_None, nsGkAtoms::formaction)) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsCOMPtr<nsIFormControl> formControl =
|
|
|
|
do_QueryInterface(aOriginatingElement);
|
|
|
|
NS_ASSERTION(formControl && formControl->IsSubmitControl(),
|
|
|
|
"The originating element must be a submit form control!");
|
|
|
|
#endif // DEBUG
|
|
|
|
|
2018-03-22 00:39:04 +03:00
|
|
|
HTMLInputElement* inputElement =
|
|
|
|
HTMLInputElement::FromNode(aOriginatingElement);
|
2010-10-29 23:49:42 +04:00
|
|
|
if (inputElement) {
|
|
|
|
inputElement->GetFormAction(action);
|
|
|
|
} else {
|
2018-03-22 00:39:04 +03:00
|
|
|
auto buttonElement = HTMLButtonElement::FromNode(aOriginatingElement);
|
2010-10-29 23:49:42 +04:00
|
|
|
if (buttonElement) {
|
|
|
|
buttonElement->GetFormAction(action);
|
|
|
|
} else {
|
|
|
|
NS_ERROR("Originating element must be an input or button element!");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2010-08-20 03:23:59 +04:00
|
|
|
}
|
|
|
|
} else {
|
2010-10-29 23:49:42 +04:00
|
|
|
GetAction(action);
|
2010-08-20 03:23:59 +04:00
|
|
|
}
|
2003-03-07 02:03:49 +03:00
|
|
|
|
|
|
|
//
|
|
|
|
// Form the full action URL
|
|
|
|
//
|
|
|
|
|
|
|
|
// Get the document to form the URL.
|
|
|
|
// We'll also need it later to get the DOM window when notifying form submit
|
|
|
|
// observers (bug 33203)
|
2018-07-04 19:18:57 +03:00
|
|
|
if (!IsInComposedDoc()) {
|
2003-03-07 02:03:49 +03:00
|
|
|
return NS_OK; // No doc means don't submit, see Bug 28988
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get base URL
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* document = OwnerDoc();
|
2004-08-10 14:22:36 +04:00
|
|
|
nsIURI* docURI = document->GetDocumentURI();
|
2004-01-10 02:54:21 +03:00
|
|
|
NS_ENSURE_TRUE(docURI, NS_ERROR_UNEXPECTED);
|
2003-03-07 02:03:49 +03:00
|
|
|
|
|
|
|
// If an action is not specified and we are inside
|
|
|
|
// a HTML document then reload the URL. This makes us
|
|
|
|
// compatible with 4.x browsers.
|
|
|
|
// If we are in some other type of document such as XML or
|
|
|
|
// XUL, do nothing. This prevents undesirable reloading of
|
|
|
|
// a document inside XUL.
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> actionURL;
|
|
|
|
if (action.IsEmpty()) {
|
2019-06-04 20:27:43 +03:00
|
|
|
if (!document->IsHTMLOrXHTML()) {
|
2003-03-07 02:03:49 +03:00
|
|
|
// Must be a XML, XUL or other non-HTML document type
|
|
|
|
// so do nothing.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-06-14 14:05:43 +03:00
|
|
|
actionURL = docURI;
|
2003-03-07 02:03:49 +03:00
|
|
|
} else {
|
2019-07-15 21:29:05 +03:00
|
|
|
nsIURI* baseURL = GetBaseURI();
|
2003-03-07 02:03:49 +03:00
|
|
|
NS_ASSERTION(baseURL, "No Base URL found in Form Submit!\n");
|
|
|
|
if (!baseURL) {
|
|
|
|
return NS_OK; // No base URL -> exit early, see Bug 30721
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
rv = NS_NewURI(getter_AddRefs(actionURL), action, nullptr, baseURL);
|
2003-03-07 02:03:49 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Verify the URL should be reached
|
|
|
|
//
|
|
|
|
// Get security manager, check to see if access to action URI is allowed.
|
|
|
|
//
|
2003-10-30 06:01:25 +03:00
|
|
|
nsIScriptSecurityManager* securityManager =
|
2005-10-14 13:07:29 +04:00
|
|
|
nsContentUtils::GetSecurityManager();
|
2006-04-27 22:21:11 +04:00
|
|
|
rv = securityManager->CheckLoadURIWithPrincipal(
|
2019-12-12 19:41:19 +03:00
|
|
|
NodePrincipal(), actionURL, nsIScriptSecurityManager::STANDARD,
|
|
|
|
OwnerDoc()->InnerWindowID());
|
2003-03-07 02:03:49 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2015-07-10 19:15:46 +03:00
|
|
|
// Potentially the page uses the CSP directive 'upgrade-insecure-requests'. In
|
|
|
|
// such a case we have to upgrade the action url from http:// to https://.
|
|
|
|
// If the actionURL is not http, then there is nothing to do.
|
2019-08-02 11:54:18 +03:00
|
|
|
bool isHttpScheme = actionURL->SchemeIs("http");
|
2016-01-14 23:38:15 +03:00
|
|
|
if (isHttpScheme && document->GetUpgradeInsecureRequests(false)) {
|
2015-07-10 19:15:46 +03:00
|
|
|
// let's use the old specification before the upgrade for logging
|
2019-06-11 18:51:51 +03:00
|
|
|
AutoTArray<nsString, 2> params;
|
2015-07-10 19:15:46 +03:00
|
|
|
nsAutoCString spec;
|
|
|
|
rv = actionURL->GetSpec(spec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2019-06-11 18:51:51 +03:00
|
|
|
CopyUTF8toUTF16(spec, *params.AppendElement());
|
2015-07-10 19:15:46 +03:00
|
|
|
|
|
|
|
// upgrade the actionURL from http:// to use https://
|
2016-03-11 02:23:46 +03:00
|
|
|
nsCOMPtr<nsIURI> upgradedActionURL;
|
|
|
|
rv = NS_GetSecureUpgradedURI(actionURL, getter_AddRefs(upgradedActionURL));
|
2015-07-10 19:15:46 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2020-02-13 17:38:48 +03:00
|
|
|
actionURL = std::move(upgradedActionURL);
|
2015-07-10 19:15:46 +03:00
|
|
|
|
|
|
|
// let's log a message to the console that we are upgrading a request
|
|
|
|
nsAutoCString scheme;
|
|
|
|
rv = actionURL->GetScheme(scheme);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2019-06-11 18:51:51 +03:00
|
|
|
CopyUTF8toUTF16(scheme, *params.AppendElement());
|
2015-07-10 19:15:46 +03:00
|
|
|
|
2017-07-12 08:13:37 +03:00
|
|
|
CSP_LogLocalizedStr(
|
2019-06-11 18:51:51 +03:00
|
|
|
"upgradeInsecureRequest", params,
|
2015-07-10 19:15:46 +03:00
|
|
|
EmptyString(), // aSourceFile
|
|
|
|
EmptyString(), // aScriptSample
|
|
|
|
0, // aLineNumber
|
|
|
|
0, // aColumnNumber
|
2018-07-20 20:57:21 +03:00
|
|
|
nsIScriptError::warningFlag,
|
|
|
|
NS_LITERAL_CSTRING("upgradeInsecureRequest"), document->InnerWindowID(),
|
2018-03-13 08:40:38 +03:00
|
|
|
!!document->NodePrincipal()->OriginAttributesRef().mPrivateBrowsingId);
|
2015-07-10 19:15:46 +03:00
|
|
|
}
|
|
|
|
|
2003-03-07 02:03:49 +03:00
|
|
|
//
|
|
|
|
// Assign to the output
|
|
|
|
//
|
2015-03-31 17:03:49 +03:00
|
|
|
actionURL.forget(aActionURL);
|
2003-03-07 02:03:49 +03:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2006-08-16 07:20:19 +04:00
|
|
|
NS_IMETHODIMP_(nsIFormControl*)
|
2013-06-19 18:24:37 +04:00
|
|
|
HTMLFormElement::GetDefaultSubmitElement() const {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(mDefaultSubmitElement == mFirstSubmitInElements ||
|
|
|
|
mDefaultSubmitElement == mFirstSubmitNotInElements,
|
|
|
|
"What happened here?");
|
2016-04-12 14:02:42 +03:00
|
|
|
|
2006-08-16 07:20:19 +04:00
|
|
|
return mDefaultSubmitElement;
|
|
|
|
}
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
bool HTMLFormElement::IsDefaultSubmitElement(
|
|
|
|
const nsIFormControl* aControl) const {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(aControl, "Unexpected call");
|
2009-09-18 22:52:27 +04:00
|
|
|
|
|
|
|
if (aControl == mDefaultSubmitElement) {
|
|
|
|
// Yes, it is
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2009-09-18 22:52:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mDefaultSubmitElement || (aControl != mFirstSubmitInElements &&
|
|
|
|
aControl != mFirstSubmitNotInElements)) {
|
|
|
|
// It isn't
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-09-18 22:52:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// mDefaultSubmitElement is null, but we have a non-null submit around
|
|
|
|
// (aControl, in fact). figure out whether it's in fact the default submit
|
|
|
|
// and just hasn't been set that way yet. Note that we can't just call
|
|
|
|
// HandleDefaultSubmitRemoval because we might need to notify to handle that
|
|
|
|
// correctly and we don't know whether that's safe right here.
|
|
|
|
if (!mFirstSubmitInElements || !mFirstSubmitNotInElements) {
|
|
|
|
// We only have one first submit; aControl has to be it
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2009-09-18 22:52:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// We have both kinds of submits. Check which comes first.
|
|
|
|
nsIFormControl* defaultSubmit =
|
|
|
|
CompareFormControlPosition(mFirstSubmitInElements,
|
|
|
|
mFirstSubmitNotInElements, this) < 0
|
|
|
|
? mFirstSubmitInElements
|
|
|
|
: mFirstSubmitNotInElements;
|
|
|
|
return aControl == defaultSubmit;
|
|
|
|
}
|
|
|
|
|
2013-10-16 18:39:45 +04:00
|
|
|
bool HTMLFormElement::ImplicitSubmissionIsDisabled() const {
|
2006-09-18 08:53:54 +04:00
|
|
|
// Input text controls are always in the elements list.
|
2013-10-16 18:39:45 +04:00
|
|
|
uint32_t numDisablingControlsFound = 0;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t length = mControls->mElements.Length();
|
2013-10-16 18:39:45 +04:00
|
|
|
for (uint32_t i = 0; i < length && numDisablingControlsFound < 2; ++i) {
|
2020-01-14 22:01:05 +03:00
|
|
|
if (mControls->mElements[i]->IsSingleLineTextControl(false)) {
|
2013-10-16 18:39:45 +04:00
|
|
|
numDisablingControlsFound++;
|
2006-09-18 08:53:54 +04:00
|
|
|
}
|
|
|
|
}
|
2014-07-24 23:47:46 +04:00
|
|
|
return numDisablingControlsFound != 1;
|
2006-09-18 08:53:54 +04:00
|
|
|
}
|
|
|
|
|
2017-10-01 16:57:16 +03:00
|
|
|
bool HTMLFormElement::IsLastActiveElement(
|
|
|
|
const nsIFormControl* aControl) const {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(aControl, "Unexpected call");
|
2017-10-01 16:57:16 +03:00
|
|
|
|
|
|
|
for (auto* element : Reversed(mControls->mElements)) {
|
2019-04-05 11:14:47 +03:00
|
|
|
// XXX How about date/time control?
|
2020-01-14 22:01:05 +03:00
|
|
|
if (element->IsTextControl(false) && !element->IsDisabled()) {
|
2017-10-01 16:57:16 +03:00
|
|
|
return element == aControl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
int32_t HTMLFormElement::Length() { return mControls->Length(); }
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
void HTMLFormElement::ForgetCurrentSubmission() {
|
2011-10-17 18:59:28 +04:00
|
|
|
mNotifiedObservers = false;
|
|
|
|
mIsSubmitting = false;
|
2012-07-30 18:20:58 +04:00
|
|
|
mSubmittingRequest = nullptr;
|
2007-11-30 20:57:03 +03:00
|
|
|
nsCOMPtr<nsIWebProgress> webProgress = do_QueryReferent(mWebProgress);
|
|
|
|
if (webProgress) {
|
|
|
|
webProgress->RemoveProgressListener(this);
|
2002-08-20 06:35:39 +04:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
mWebProgress = nullptr;
|
2002-08-20 06:35:39 +04:00
|
|
|
}
|
|
|
|
|
2018-08-16 22:20:54 +03:00
|
|
|
bool HTMLFormElement::CheckFormValidity(
|
|
|
|
nsTArray<RefPtr<Element>>* aInvalidElements) const {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ret = true;
|
2010-08-21 22:51:38 +04:00
|
|
|
|
2017-07-28 18:33:41 +03:00
|
|
|
// This shouldn't be called recursively, so use a rather large value
|
|
|
|
// for the preallocated buffer.
|
2017-07-28 18:38:26 +03:00
|
|
|
AutoTArray<RefPtr<nsGenericHTMLFormElement>, 100> sortedControls;
|
2010-08-21 22:51:38 +04:00
|
|
|
if (NS_FAILED(mControls->GetSortedControls(sortedControls))) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-08-21 22:51:38 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t len = sortedControls.Length();
|
2010-08-21 22:51:38 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < len; ++i) {
|
2013-08-08 00:23:08 +04:00
|
|
|
nsCOMPtr<nsIConstraintValidation> cvElmt =
|
|
|
|
do_QueryObject(sortedControls[i]);
|
2010-08-21 22:51:38 +04:00
|
|
|
if (cvElmt && cvElmt->IsCandidateForConstraintValidation() &&
|
|
|
|
!cvElmt->IsValid()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
ret = false;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool defaultAction = true;
|
2011-10-18 14:53:36 +04:00
|
|
|
nsContentUtils::DispatchTrustedEvent(
|
|
|
|
sortedControls[i]->OwnerDoc(),
|
2010-08-21 22:51:38 +04:00
|
|
|
static_cast<nsIContent*>(sortedControls[i]),
|
2018-06-25 19:23:50 +03:00
|
|
|
NS_LITERAL_STRING("invalid"), CanBubble::eNo, Cancelable::eYes,
|
|
|
|
&defaultAction);
|
2010-09-11 08:07:41 +04:00
|
|
|
|
|
|
|
// Add all unhandled invalid controls to aInvalidElements if the caller
|
|
|
|
// requested them.
|
|
|
|
if (defaultAction && aInvalidElements) {
|
2018-08-16 22:20:54 +03:00
|
|
|
aInvalidElements->AppendElement(sortedControls[i]);
|
2010-09-11 08:07:41 +04:00
|
|
|
}
|
2010-08-21 22:51:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
bool HTMLFormElement::CheckValidFormSubmission() {
|
2010-09-11 08:07:41 +04:00
|
|
|
/**
|
|
|
|
* Check for form validity: do not submit a form if there are unhandled
|
|
|
|
* invalid controls in the form.
|
|
|
|
* This should not be done if the form has been submitted with .submit().
|
|
|
|
*
|
|
|
|
* NOTE: for the moment, we are also checking that there is an observer for
|
|
|
|
* NS_INVALIDFORMSUBMIT_SUBJECT so it will prevent blocking form submission
|
|
|
|
* if the browser does not have implemented a UI yet.
|
|
|
|
*
|
|
|
|
* TODO: the check for observer should be removed later when HTML5 Forms will
|
|
|
|
* be spread enough and authors will assume forms can't be submitted when
|
|
|
|
* invalid. See bug 587671.
|
|
|
|
*/
|
|
|
|
|
2010-09-11 08:11:58 +04:00
|
|
|
NS_ASSERTION(!HasAttr(kNameSpaceID_None, nsGkAtoms::novalidate),
|
|
|
|
"We shouldn't be there if novalidate is set!");
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
// When .submit() is called aEvent = nullptr so we can rely on that to know if
|
2010-09-11 08:07:41 +04:00
|
|
|
// we have to check the validity of the form.
|
|
|
|
nsCOMPtr<nsIObserverService> service =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
if (!service) {
|
|
|
|
NS_WARNING("No observer service available!");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-08-16 05:22:30 +03:00
|
|
|
AutoTArray<RefPtr<Element>, 32> invalidElements;
|
|
|
|
if (CheckFormValidity(&invalidElements)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For the first invalid submission, we should update element states.
|
|
|
|
// We have to do that _before_ calling the observers so we are sure they
|
|
|
|
// will not interfere (like focusing the element).
|
|
|
|
if (!mEverTriedInvalidSubmit) {
|
|
|
|
mEverTriedInvalidSubmit = true;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We are going to call update states assuming elements want to
|
|
|
|
* be notified because we can't know.
|
|
|
|
* Submissions shouldn't happen during parsing so it _should_ be safe.
|
|
|
|
*/
|
|
|
|
|
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
|
|
|
|
|
|
|
for (uint32_t i = 0, length = mControls->mElements.Length(); i < length;
|
|
|
|
++i) {
|
|
|
|
// Input elements can trigger a form submission and we want to
|
|
|
|
// update the style in that case.
|
|
|
|
if (mControls->mElements[i]->IsHTMLElement(nsGkAtoms::input) &&
|
|
|
|
// We don't use nsContentUtils::IsFocusedContent here, because it
|
|
|
|
// doesn't really do what we want for number controls: it's true
|
|
|
|
// for the anonymous textnode inside, but not the number control
|
|
|
|
// itself. We can use the focus state, though, because that gets
|
|
|
|
// synced to the number control by the anonymous text control.
|
|
|
|
mControls->mElements[i]->State().HasState(NS_EVENT_STATE_FOCUS)) {
|
|
|
|
static_cast<HTMLInputElement*>(mControls->mElements[i])
|
|
|
|
->UpdateValidityUIBits(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
mControls->mElements[i]->UpdateState(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Because of backward compatibility, <input type='image'> is not in
|
|
|
|
// elements but can be invalid.
|
|
|
|
// TODO: should probably be removed when bug 606491 will be fixed.
|
|
|
|
for (uint32_t i = 0, length = mControls->mNotInElements.Length();
|
|
|
|
i < length; ++i) {
|
|
|
|
mControls->mNotInElements[i]->UpdateState(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoJSAPI jsapi;
|
|
|
|
if (!jsapi.Init(GetOwnerGlobal())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
JS::Rooted<JS::Value> detail(jsapi.cx());
|
|
|
|
if (!ToJSValue(jsapi.cx(), invalidElements, &detail)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<CustomEvent> event =
|
|
|
|
NS_NewDOMCustomEvent(OwnerDoc(), nullptr, nullptr);
|
|
|
|
event->InitCustomEvent(jsapi.cx(), NS_LITERAL_STRING("MozInvalidForm"),
|
|
|
|
/* CanBubble */ true,
|
|
|
|
/* Cancelable */ true, detail);
|
|
|
|
event->SetTrusted(true);
|
|
|
|
event->WidgetEventPtr()->mFlags.mOnlyChromeDispatch = true;
|
|
|
|
|
|
|
|
DispatchEvent(*event);
|
|
|
|
|
|
|
|
bool result = !event->DefaultPrevented();
|
|
|
|
|
2010-09-11 08:07:41 +04:00
|
|
|
nsCOMPtr<nsISimpleEnumerator> theEnum;
|
|
|
|
nsresult rv = service->EnumerateObservers(NS_INVALIDFORMSUBMIT_SUBJECT,
|
|
|
|
getter_AddRefs(theEnum));
|
2018-08-16 05:22:30 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, result);
|
2010-09-11 08:07:41 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool hasObserver = false;
|
2010-09-11 08:07:41 +04:00
|
|
|
rv = theEnum->HasMoreElements(&hasObserver);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && hasObserver) {
|
2018-08-16 05:22:30 +03:00
|
|
|
result = false;
|
2010-09-11 08:07:41 +04:00
|
|
|
|
2018-08-16 05:22:30 +03:00
|
|
|
nsCOMPtr<nsISupports> inst;
|
|
|
|
nsCOMPtr<nsIFormSubmitObserver> observer;
|
|
|
|
bool more = true;
|
|
|
|
while (NS_SUCCEEDED(theEnum->HasMoreElements(&more)) && more) {
|
|
|
|
theEnum->GetNext(getter_AddRefs(inst));
|
|
|
|
observer = do_QueryInterface(inst);
|
2010-11-24 02:50:53 +03:00
|
|
|
|
2018-08-16 05:22:30 +03:00
|
|
|
if (observer) {
|
|
|
|
observer->NotifyInvalidSubmit(this, invalidElements);
|
2010-11-24 02:50:53 +03:00
|
|
|
}
|
2010-09-11 08:07:41 +04:00
|
|
|
}
|
2018-08-16 05:22:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (result) {
|
2010-09-11 08:07:41 +04:00
|
|
|
NS_WARNING(
|
|
|
|
"There is no observer for \"invalidformsubmit\". \
|
|
|
|
One should be implemented!");
|
|
|
|
}
|
|
|
|
|
2018-08-16 05:22:30 +03:00
|
|
|
return result;
|
2010-09-11 08:07:41 +04:00
|
|
|
}
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
void HTMLFormElement::UpdateValidity(bool aElementValidity) {
|
2010-09-10 09:08:56 +04:00
|
|
|
if (aElementValidity) {
|
|
|
|
--mInvalidElementsCount;
|
|
|
|
} else {
|
|
|
|
++mInvalidElementsCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(mInvalidElementsCount >= 0, "Something went seriously wrong!");
|
|
|
|
|
|
|
|
// The form validity has just changed if:
|
|
|
|
// - there are no more invalid elements ;
|
|
|
|
// - or there is one invalid elmement and an element just became invalid.
|
|
|
|
// If we have invalid elements and we used to before as well, do nothing.
|
|
|
|
if (mInvalidElementsCount &&
|
|
|
|
(mInvalidElementsCount != 1 || aElementValidity)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-06-01 05:46:57 +04:00
|
|
|
* We are going to update states assuming submit controls want to
|
2010-09-10 09:08:56 +04:00
|
|
|
* be notified because we can't know.
|
|
|
|
* UpdateValidity shouldn't be called so much during parsing so it _should_
|
|
|
|
* be safe.
|
|
|
|
*/
|
|
|
|
|
2011-06-01 01:38:25 +04:00
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
2010-09-10 09:08:56 +04:00
|
|
|
|
|
|
|
// Inform submit controls that the form validity has changed.
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0, length = mControls->mElements.Length(); i < length;
|
2010-09-10 09:08:56 +04:00
|
|
|
++i) {
|
|
|
|
if (mControls->mElements[i]->IsSubmitControl()) {
|
2011-06-01 05:46:57 +04:00
|
|
|
mControls->mElements[i]->UpdateState(true);
|
2010-09-10 09:08:56 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Because of backward compatibility, <input type='image'> is not in elements
|
|
|
|
// so we have to check for controls not in elements too.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t length = mControls->mNotInElements.Length();
|
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
2010-09-10 09:08:56 +04:00
|
|
|
if (mControls->mNotInElements[i]->IsSubmitControl()) {
|
2011-06-01 05:46:57 +04:00
|
|
|
mControls->mNotInElements[i]->UpdateState(true);
|
2010-09-10 09:08:56 +04:00
|
|
|
}
|
|
|
|
}
|
2012-02-07 16:51:49 +04:00
|
|
|
|
|
|
|
UpdateState(true);
|
2010-09-10 09:08:56 +04:00
|
|
|
}
|
|
|
|
|
2002-03-13 09:08:56 +03:00
|
|
|
// nsIWebProgressListener
|
|
|
|
NS_IMETHODIMP
|
2013-06-19 18:24:37 +04:00
|
|
|
HTMLFormElement::OnStateChange(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest, uint32_t aStateFlags,
|
|
|
|
nsresult aStatus) {
|
2002-03-13 09:08:56 +03:00
|
|
|
// If STATE_STOP is never fired for any reason (redirect? Failed state
|
|
|
|
// change?) the form element will leak. It will be kept around by the
|
|
|
|
// nsIWebProgressListener (assuming it keeps a strong pointer). We will
|
|
|
|
// consequently leak the request.
|
|
|
|
if (aRequest == mSubmittingRequest &&
|
|
|
|
aStateFlags & nsIWebProgressListener::STATE_STOP) {
|
2002-08-20 06:35:39 +04:00
|
|
|
ForgetCurrentSubmission();
|
2002-03-13 09:08:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-06-19 18:24:37 +04:00
|
|
|
HTMLFormElement::OnProgressChange(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest,
|
|
|
|
int32_t aCurSelfProgress,
|
|
|
|
int32_t aMaxSelfProgress,
|
|
|
|
int32_t aCurTotalProgress,
|
|
|
|
int32_t aMaxTotalProgress) {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("notification excluded in AddProgressListener(...)");
|
2002-03-13 09:08:56 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-06-19 18:24:37 +04:00
|
|
|
HTMLFormElement::OnLocationChange(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest, nsIURI* location,
|
|
|
|
uint32_t aFlags) {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("notification excluded in AddProgressListener(...)");
|
2002-03-13 09:08:56 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-06-19 18:24:37 +04:00
|
|
|
HTMLFormElement::OnStatusChange(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest, nsresult aStatus,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* aMessage) {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("notification excluded in AddProgressListener(...)");
|
2002-03-13 09:08:56 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-06-19 18:24:37 +04:00
|
|
|
HTMLFormElement::OnSecurityChange(nsIWebProgress* aWebProgress,
|
2019-01-07 01:45:57 +03:00
|
|
|
nsIRequest* aRequest, uint32_t aState) {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("notification excluded in AddProgressListener(...)");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLFormElement::OnContentBlockingEvent(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest, uint32_t aEvent) {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("notification excluded in AddProgressListener(...)");
|
2002-03-13 09:08:56 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-06-18 16:53:23 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_IMETHODIMP_(int32_t)
|
2013-06-19 18:24:37 +04:00
|
|
|
HTMLFormElement::IndexOfControl(nsIFormControl* aControl) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t index = 0;
|
2012-07-20 15:16:17 +04:00
|
|
|
return mControls->IndexOfControl(aControl, &index) == NS_OK ? index : 0;
|
2001-05-30 15:26:21 +04:00
|
|
|
}
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
void HTMLFormElement::SetCurrentRadioButton(const nsAString& aName,
|
2013-08-10 05:17:51 +04:00
|
|
|
HTMLInputElement* aRadio) {
|
2020-02-25 20:03:36 +03:00
|
|
|
mSelectedRadioButtons.Put(aName, RefPtr{aRadio});
|
2002-03-07 23:53:40 +03:00
|
|
|
}
|
1999-10-07 04:35:04 +04:00
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
HTMLInputElement* HTMLFormElement::GetCurrentRadioButton(
|
|
|
|
const nsAString& aName) {
|
2012-08-03 14:38:52 +04:00
|
|
|
return mSelectedRadioButtons.GetWeak(aName);
|
2005-04-04 17:43:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-06-19 18:24:37 +04:00
|
|
|
HTMLFormElement::GetNextRadioButton(const nsAString& aName,
|
|
|
|
const bool aPrevious,
|
2013-08-10 05:17:51 +04:00
|
|
|
HTMLInputElement* aFocusedRadio,
|
|
|
|
HTMLInputElement** aRadioOut) {
|
2004-07-05 05:31:30 +04:00
|
|
|
// Return the radio button relative to the focused radio button.
|
|
|
|
// If no radio is focused, get the radio relative to the selected one.
|
2012-07-30 18:20:58 +04:00
|
|
|
*aRadioOut = nullptr;
|
2004-07-05 05:31:30 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<HTMLInputElement> currentRadio;
|
2004-07-05 05:31:30 +04:00
|
|
|
if (aFocusedRadio) {
|
|
|
|
currentRadio = aFocusedRadio;
|
|
|
|
} else {
|
|
|
|
mSelectedRadioButtons.Get(aName, getter_AddRefs(currentRadio));
|
|
|
|
}
|
|
|
|
|
2013-04-04 11:03:12 +04:00
|
|
|
nsCOMPtr<nsISupports> itemWithName = DoResolveName(aName, true);
|
2009-10-30 04:49:11 +03:00
|
|
|
nsCOMPtr<nsINodeList> radioGroup(do_QueryInterface(itemWithName));
|
2004-07-05 05:31:30 +04:00
|
|
|
|
|
|
|
if (!radioGroup) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2013-08-10 05:17:51 +04:00
|
|
|
int32_t index = radioGroup->IndexOf(currentRadio);
|
2004-07-05 05:31:30 +04:00
|
|
|
if (index < 0) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2018-03-20 21:02:08 +03:00
|
|
|
uint32_t numRadios = radioGroup->Length();
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<HTMLInputElement> radio;
|
2004-07-05 05:31:30 +04:00
|
|
|
|
2014-04-27 05:55:00 +04:00
|
|
|
bool isRadio = false;
|
2004-07-05 05:31:30 +04:00
|
|
|
do {
|
|
|
|
if (aPrevious) {
|
|
|
|
if (--index < 0) {
|
|
|
|
index = numRadios - 1;
|
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
} else if (++index >= (int32_t)numRadios) {
|
2004-07-05 05:31:30 +04:00
|
|
|
index = 0;
|
|
|
|
}
|
2018-03-22 00:39:04 +03:00
|
|
|
radio = HTMLInputElement::FromNodeOrNull(radioGroup->Item(index));
|
2017-04-01 05:49:00 +03:00
|
|
|
isRadio = radio && radio->ControlType() == NS_FORM_INPUT_RADIO;
|
2014-10-07 05:51:00 +04:00
|
|
|
if (!isRadio) {
|
2006-06-29 07:26:29 +04:00
|
|
|
continue;
|
2014-10-07 05:51:00 +04:00
|
|
|
}
|
2006-06-29 07:26:29 +04:00
|
|
|
|
2014-10-07 05:51:00 +04:00
|
|
|
nsAutoString name;
|
|
|
|
radio->GetName(name);
|
|
|
|
isRadio = aName.Equals(name);
|
|
|
|
} while (!isRadio || (radio->Disabled() && radio != currentRadio));
|
2004-07-05 05:31:30 +04:00
|
|
|
|
|
|
|
NS_IF_ADDREF(*aRadioOut = radio);
|
2002-03-07 23:53:40 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-06-19 18:24:37 +04:00
|
|
|
HTMLFormElement::WalkRadioGroup(const nsAString& aName,
|
|
|
|
nsIRadioVisitor* aVisitor, bool aFlushContent) {
|
2002-03-07 23:53:40 +03:00
|
|
|
if (aName.IsEmpty()) {
|
|
|
|
//
|
|
|
|
// XXX If the name is empty, it's not stored in the control list. There
|
|
|
|
// *must* be a more efficient way to do this.
|
|
|
|
//
|
|
|
|
nsCOMPtr<nsIFormControl> control;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t len = GetElementCount();
|
|
|
|
for (uint32_t i = 0; i < len; i++) {
|
2009-10-30 04:49:11 +03:00
|
|
|
control = GetElementAt(i);
|
2017-04-01 05:49:00 +03:00
|
|
|
if (control->ControlType() == NS_FORM_INPUT_RADIO) {
|
2017-12-07 21:13:50 +03:00
|
|
|
nsCOMPtr<Element> controlElement = do_QueryInterface(control);
|
|
|
|
if (controlElement &&
|
|
|
|
controlElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::name,
|
2011-11-16 11:50:19 +04:00
|
|
|
EmptyString(), eCaseMatters) &&
|
|
|
|
!aVisitor->Visit(control)) {
|
|
|
|
break;
|
2002-03-07 23:53:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-11-16 11:50:19 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the control / list of controls from the form using form["name"]
|
|
|
|
nsCOMPtr<nsISupports> item = DoResolveName(aName, aFlushContent);
|
|
|
|
if (!item) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If it's just a lone radio button, then select it.
|
|
|
|
nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(item);
|
|
|
|
if (formControl) {
|
2017-04-01 05:49:00 +03:00
|
|
|
if (formControl->ControlType() == NS_FORM_INPUT_RADIO) {
|
2011-11-16 11:50:19 +04:00
|
|
|
aVisitor->Visit(formControl);
|
2002-03-07 23:53:40 +03:00
|
|
|
}
|
2011-11-16 11:50:19 +04:00
|
|
|
return NS_OK;
|
2002-03-07 23:53:40 +03:00
|
|
|
}
|
|
|
|
|
2018-03-20 21:02:08 +03:00
|
|
|
nsCOMPtr<nsINodeList> nodeList = do_QueryInterface(item);
|
2011-11-16 11:50:19 +04:00
|
|
|
if (!nodeList) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2018-03-20 21:02:08 +03:00
|
|
|
uint32_t length = nodeList->Length();
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < length; i++) {
|
2018-03-20 21:02:08 +03:00
|
|
|
nsIContent* node = nodeList->Item(i);
|
2011-11-16 11:50:19 +04:00
|
|
|
nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(node);
|
2017-04-01 05:49:00 +03:00
|
|
|
if (formControl && formControl->ControlType() == NS_FORM_INPUT_RADIO &&
|
2011-11-16 11:50:19 +04:00
|
|
|
!aVisitor->Visit(formControl)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2002-03-07 23:53:40 +03:00
|
|
|
}
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
void HTMLFormElement::AddToRadioGroup(const nsAString& aName,
|
2017-08-03 09:39:00 +03:00
|
|
|
HTMLInputElement* aRadio) {
|
|
|
|
if (aRadio->IsRequired()) {
|
2017-06-29 21:53:46 +03:00
|
|
|
auto entry = mRequiredRadioButtonCounts.LookupForAdd(aName);
|
|
|
|
if (!entry) {
|
|
|
|
entry.OrInsert([]() { return 1; });
|
|
|
|
} else {
|
|
|
|
++entry.Data();
|
|
|
|
}
|
2011-02-25 21:12:47 +03:00
|
|
|
}
|
2002-07-21 03:09:24 +04:00
|
|
|
}
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
void HTMLFormElement::RemoveFromRadioGroup(const nsAString& aName,
|
2017-08-03 09:39:00 +03:00
|
|
|
HTMLInputElement* aRadio) {
|
|
|
|
if (aRadio->IsRequired()) {
|
2017-06-29 21:53:46 +03:00
|
|
|
auto entry = mRequiredRadioButtonCounts.Lookup(aName);
|
|
|
|
if (!entry) {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("At least one radio button has to be required!");
|
2011-02-25 21:12:47 +03:00
|
|
|
} else {
|
2017-06-29 21:53:46 +03:00
|
|
|
MOZ_ASSERT(entry.Data() >= 1,
|
|
|
|
"At least one radio button has to be required!");
|
|
|
|
if (entry.Data() <= 1) {
|
|
|
|
entry.Remove();
|
|
|
|
} else {
|
|
|
|
--entry.Data();
|
|
|
|
}
|
2011-02-25 21:12:47 +03:00
|
|
|
}
|
|
|
|
}
|
2002-07-21 03:09:24 +04:00
|
|
|
}
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
uint32_t HTMLFormElement::GetRequiredRadioCount(const nsAString& aName) const {
|
2011-02-25 21:12:47 +03:00
|
|
|
return mRequiredRadioButtonCounts.Get(aName);
|
|
|
|
}
|
|
|
|
|
2014-11-28 04:40:00 +03:00
|
|
|
void HTMLFormElement::RadioRequiredWillChange(const nsAString& aName,
|
|
|
|
bool aRequiredAdded) {
|
|
|
|
if (aRequiredAdded) {
|
2011-02-25 21:12:47 +03:00
|
|
|
mRequiredRadioButtonCounts.Put(aName,
|
|
|
|
mRequiredRadioButtonCounts.Get(aName) + 1);
|
|
|
|
} else {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t requiredNb = mRequiredRadioButtonCounts.Get(aName);
|
2011-02-25 21:12:47 +03:00
|
|
|
NS_ASSERTION(requiredNb >= 1,
|
|
|
|
"At least one radio button has to be required!");
|
|
|
|
if (requiredNb == 1) {
|
|
|
|
mRequiredRadioButtonCounts.Remove(aName);
|
|
|
|
} else {
|
|
|
|
mRequiredRadioButtonCounts.Put(aName, requiredNb - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
bool HTMLFormElement::GetValueMissingState(const nsAString& aName) const {
|
2011-02-25 21:16:04 +03:00
|
|
|
return mValueMissingRadioGroups.Get(aName);
|
|
|
|
}
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
void HTMLFormElement::SetValueMissingState(const nsAString& aName,
|
|
|
|
bool aValue) {
|
2011-02-25 21:16:04 +03:00
|
|
|
mValueMissingRadioGroups.Put(aName, aValue);
|
|
|
|
}
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
EventStates HTMLFormElement::IntrinsicState() const {
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates state = nsGenericHTMLElement::IntrinsicState();
|
2012-02-07 16:51:49 +04:00
|
|
|
|
|
|
|
if (mInvalidElementsCount) {
|
|
|
|
state |= NS_EVENT_STATE_INVALID;
|
|
|
|
} else {
|
|
|
|
state |= NS_EVENT_STATE_VALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
2011-02-25 21:12:47 +03:00
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
void HTMLFormElement::Clear() {
|
2013-06-18 16:53:23 +04:00
|
|
|
for (int32_t i = mImageElements.Length() - 1; i >= 0; i--) {
|
|
|
|
mImageElements[i]->ClearForm(false);
|
|
|
|
}
|
|
|
|
mImageElements.Clear();
|
|
|
|
mImageNameLookupTable.Clear();
|
2013-06-18 16:54:27 +04:00
|
|
|
mPastNameLookupTable.Clear();
|
2013-06-18 16:53:23 +04:00
|
|
|
}
|
|
|
|
|
2014-09-17 17:46:24 +04:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct PositionComparator {
|
|
|
|
nsIContent* const mElement;
|
2014-09-24 17:16:53 +04:00
|
|
|
explicit PositionComparator(nsIContent* const aElement)
|
|
|
|
: mElement(aElement) {}
|
2014-09-17 17:46:24 +04:00
|
|
|
|
|
|
|
int operator()(nsIContent* aElement) const {
|
|
|
|
if (mElement == aElement) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (nsContentUtils::PositionIsBefore(mElement, aElement)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-06-29 21:53:46 +03:00
|
|
|
struct RadioNodeListAdaptor {
|
|
|
|
RadioNodeList* const mList;
|
|
|
|
explicit RadioNodeListAdaptor(RadioNodeList* aList) : mList(aList) {}
|
2014-09-17 17:46:24 +04:00
|
|
|
nsIContent* operator[](size_t aIdx) const { return mList->Item(aIdx); }
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
nsresult HTMLFormElement::AddElementToTableInternal(
|
2013-06-18 16:53:23 +04:00
|
|
|
nsInterfaceHashtable<nsStringHashKey, nsISupports>& aTable,
|
2013-06-19 18:24:37 +04:00
|
|
|
nsIContent* aChild, const nsAString& aName) {
|
2017-06-29 21:53:46 +03:00
|
|
|
auto entry = aTable.LookupForAdd(aName);
|
|
|
|
if (!entry) {
|
2013-06-18 16:53:23 +04:00
|
|
|
// No entry found, add the element
|
2017-06-29 21:53:46 +03:00
|
|
|
entry.OrInsert([&aChild]() { return aChild; });
|
2013-06-19 18:24:37 +04:00
|
|
|
++mExpandoAndGeneration.generation;
|
2000-06-02 02:55:19 +04:00
|
|
|
} else {
|
|
|
|
// Found something in the hash, check its type
|
2017-06-29 21:53:46 +03:00
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(entry.Data());
|
2000-06-02 02:55:19 +04:00
|
|
|
|
|
|
|
if (content) {
|
2000-06-10 02:47:29 +04:00
|
|
|
// Check if the new content is the same as the one we found in the
|
|
|
|
// hash, if it is then we leave it in the hash as it is, this will
|
|
|
|
// happen if a form control has both a name and an id with the same
|
|
|
|
// value
|
2009-10-30 04:49:11 +03:00
|
|
|
if (content == aChild) {
|
2000-06-10 02:47:29 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-06-02 02:55:19 +04:00
|
|
|
// Found an element, create a list, add the element to the list and put
|
|
|
|
// the list in the hash
|
2014-07-16 20:44:19 +04:00
|
|
|
RadioNodeList* list = new RadioNodeList(this);
|
2000-06-02 02:55:19 +04:00
|
|
|
|
2012-04-03 19:37:15 +04:00
|
|
|
// If an element has a @form, we can assume it *might* be able to not have
|
|
|
|
// a parent and still be in the form.
|
2017-12-07 21:13:50 +03:00
|
|
|
NS_ASSERTION(
|
|
|
|
(content->IsElement() &&
|
|
|
|
content->AsElement()->HasAttr(kNameSpaceID_None, nsGkAtoms::form)) ||
|
2012-04-03 19:37:15 +04:00
|
|
|
content->GetParent(),
|
|
|
|
"Item in list without parent");
|
2009-07-24 17:33:20 +04:00
|
|
|
|
|
|
|
// Determine the ordering between the new and old element.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool newFirst = nsContentUtils::PositionIsBefore(aChild, content);
|
2009-07-24 17:33:20 +04:00
|
|
|
|
2013-06-18 16:53:23 +04:00
|
|
|
list->AppendElement(newFirst ? aChild : content.get());
|
|
|
|
list->AppendElement(newFirst ? content.get() : aChild);
|
2000-06-02 02:55:19 +04:00
|
|
|
|
2011-08-31 01:45:31 +04:00
|
|
|
nsCOMPtr<nsISupports> listSupports = do_QueryObject(list);
|
2001-03-22 11:51:52 +03:00
|
|
|
|
2000-06-02 02:55:19 +04:00
|
|
|
// Replace the element with the list.
|
2017-06-29 21:53:46 +03:00
|
|
|
entry.Data() = listSupports;
|
2000-06-02 02:55:19 +04:00
|
|
|
} else {
|
2017-06-29 21:53:46 +03:00
|
|
|
// There's already a list in the hash, add the child to the list.
|
|
|
|
MOZ_ASSERT(nsCOMPtr<RadioNodeList>(do_QueryInterface(entry.Data())));
|
|
|
|
auto* list = static_cast<RadioNodeList*>(entry.Data().get());
|
2000-06-02 02:55:19 +04:00
|
|
|
|
2009-07-24 17:33:20 +04:00
|
|
|
NS_ASSERTION(list->Length() > 1,
|
|
|
|
"List should have been converted back to a single element");
|
2009-11-19 23:58:46 +03:00
|
|
|
|
|
|
|
// Fast-path appends; this check is ok even if the child is
|
|
|
|
// already in the list, since if it tests true the child would
|
|
|
|
// have come at the end of the list, and the PositionIsBefore
|
|
|
|
// will test false.
|
2012-10-13 16:50:24 +04:00
|
|
|
if (nsContentUtils::PositionIsBefore(list->Item(list->Length() - 1),
|
|
|
|
aChild)) {
|
2009-11-19 23:58:46 +03:00
|
|
|
list->AppendElement(aChild);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If a control has a name equal to its id, it could be in the
|
|
|
|
// list already.
|
|
|
|
if (list->IndexOf(aChild) != -1) {
|
|
|
|
return NS_OK;
|
2000-06-10 02:47:29 +04:00
|
|
|
}
|
2009-07-24 17:33:20 +04:00
|
|
|
|
2014-09-17 17:46:24 +04:00
|
|
|
size_t idx;
|
2017-06-29 21:53:46 +03:00
|
|
|
DebugOnly<bool> found =
|
|
|
|
BinarySearchIf(RadioNodeListAdaptor(list), 0, list->Length(),
|
2014-09-17 17:46:24 +04:00
|
|
|
PositionComparator(aChild), &idx);
|
|
|
|
MOZ_ASSERT(!found, "should not have found an element");
|
|
|
|
|
|
|
|
list->InsertElementAt(aChild, idx);
|
2000-06-02 02:55:19 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-19 11:49:07 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-05-30 15:26:21 +04:00
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
nsresult HTMLFormElement::AddImageElement(HTMLImageElement* aChild) {
|
2013-06-18 16:53:23 +04:00
|
|
|
AddElementToList(mImageElements, aChild, this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
nsresult HTMLFormElement::AddImageElementToTable(HTMLImageElement* aChild,
|
|
|
|
const nsAString& aName) {
|
2013-06-19 18:24:37 +04:00
|
|
|
return AddElementToTableInternal(mImageNameLookupTable, aChild, aName);
|
2013-06-18 16:53:23 +04:00
|
|
|
}
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
nsresult HTMLFormElement::RemoveImageElement(HTMLImageElement* aChild) {
|
2016-11-21 20:34:02 +03:00
|
|
|
RemoveElementFromPastNamesMap(aChild);
|
|
|
|
|
2014-05-09 05:03:35 +04:00
|
|
|
size_t index = mImageElements.IndexOf(aChild);
|
2013-06-18 16:53:23 +04:00
|
|
|
NS_ENSURE_STATE(index != mImageElements.NoIndex);
|
|
|
|
|
|
|
|
mImageElements.RemoveElementAt(index);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
nsresult HTMLFormElement::RemoveImageElementFromTable(
|
|
|
|
HTMLImageElement* aElement, const nsAString& aName) {
|
2013-06-18 16:53:23 +04:00
|
|
|
return RemoveElementFromTableInternal(mImageNameLookupTable, aElement, aName);
|
|
|
|
}
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
void HTMLFormElement::AddToPastNamesMap(const nsAString& aName,
|
|
|
|
nsISupports* aChild) {
|
2013-06-18 16:54:27 +04:00
|
|
|
// If candidates contains exactly one node. Add a mapping from name to the
|
|
|
|
// node in candidates in the form element's past names map, replacing the
|
|
|
|
// previous entry with the same name, if any.
|
|
|
|
nsCOMPtr<nsIContent> node = do_QueryInterface(aChild);
|
|
|
|
if (node) {
|
2016-11-21 20:34:02 +03:00
|
|
|
mPastNameLookupTable.Put(aName, node);
|
|
|
|
node->SetFlags(MAY_BE_IN_PAST_NAMES_MAP);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLFormElement::RemoveElementFromPastNamesMap(Element* aElement) {
|
|
|
|
if (!aElement->HasFlag(MAY_BE_IN_PAST_NAMES_MAP)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aElement->UnsetFlags(MAY_BE_IN_PAST_NAMES_MAP);
|
|
|
|
|
|
|
|
uint32_t oldCount = mPastNameLookupTable.Count();
|
|
|
|
for (auto iter = mPastNameLookupTable.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
if (aElement == iter.Data()) {
|
|
|
|
iter.Remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (oldCount != mPastNameLookupTable.Count()) {
|
|
|
|
++mExpandoAndGeneration.generation;
|
2013-06-18 16:54:27 +04:00
|
|
|
}
|
|
|
|
}
|
2016-04-12 14:02:42 +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* HTMLFormElement::WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return HTMLFormElement_Binding::Wrap(aCx, this, aGivenProto);
|
2013-06-19 18:24:37 +04:00
|
|
|
}
|
|
|
|
|
2019-07-01 13:06:16 +03:00
|
|
|
int32_t HTMLFormElement::GetFormNumberForStateKey() {
|
|
|
|
if (mFormNumber == -1) {
|
|
|
|
mFormNumber = OwnerDoc()->GetNextFormNumber();
|
|
|
|
}
|
|
|
|
return mFormNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLFormElement::NodeInfoChanged(Document* aOldDoc) {
|
|
|
|
nsGenericHTMLElement::NodeInfoChanged(aOldDoc);
|
|
|
|
|
|
|
|
// When a <form> element is adopted into a new document, we want any state
|
|
|
|
// keys generated from it to no longer consider this element to be parser
|
|
|
|
// inserted, and so have state keys based on the position of the <form>
|
|
|
|
// element in the document, rather than the order it was inserted in.
|
|
|
|
//
|
|
|
|
// This is not strictly necessary, since we only ever look at the form number
|
|
|
|
// for parser inserted form controls, and we do that at the time the form
|
|
|
|
// control element is inserted into its original document by the parser.
|
|
|
|
mFormNumber = -1;
|
|
|
|
}
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|