зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1654683 - Avoid failing to set the search range for find due to nsRange security checks. r=smaug
We should probably switch nsRange to use CallerType instead of implicit JSContext checks? Differential Revision: https://phabricator.services.mozilla.com/D84803
This commit is contained in:
Родитель
e63a1303ef
Коммит
36cd507c54
|
@ -683,6 +683,7 @@ skip-if = toolkit == 'android' && !is_fennec # Bug 1525959
|
|||
[test_find.html]
|
||||
[test_find_nac.html]
|
||||
[test_find_bug1601118.html]
|
||||
[test_find_bug1654683.html]
|
||||
[test_focus_shadow_dom_root.html]
|
||||
[test_focus_shadow_dom.html]
|
||||
[test_focus_scrollable_input.html]
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<!doctype html>
|
||||
<meta charset="utf-8">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div class="before">
|
||||
mozilla before
|
||||
</div>
|
||||
<input value="mozilla">
|
||||
<div class="after">
|
||||
mozilla after
|
||||
</div>
|
||||
<script>
|
||||
function selectionContainedWithin(selector) {
|
||||
for (let node = getSelection().anchorNode; node; node = node.parentNode) {
|
||||
if (node.matches && node.matches(selector))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
test(function () {
|
||||
let input = document.querySelector("input");
|
||||
input.focus();
|
||||
assert_true(window.find("mozilla"), "Found the string, didn't throw");
|
||||
assert_true(selectionContainedWithin(".after"), "Should've found the following node");
|
||||
assert_true(!window.find("mozilla"), "No more matches forward");
|
||||
assert_true(window.find("mozilla", /* caseSensitive = */ false, /* backwards = */ true), "Should find stuff backwards");
|
||||
assert_true(selectionContainedWithin(".before"), "Should've found the node before the input (should not return the NAC range)");
|
||||
}, "window.find() doesn't throw if focused on an <input>");
|
||||
</script>
|
|
@ -10,6 +10,7 @@
|
|||
// else we could use nsRange.h and nsIFind.h.
|
||||
#include "nsFind.h"
|
||||
|
||||
#include "mozilla/dom/ScriptSettings.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsIInterfaceRequestorUtils.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
|
@ -448,6 +449,11 @@ nsresult nsWebBrowserFind::GetSearchLimits(nsRange* aSearchRange,
|
|||
nsCOMPtr<nsINode> node;
|
||||
uint32_t offset;
|
||||
|
||||
// Prevent the security checks in nsRange from getting into effect for the
|
||||
// purposes of determining the search range. These ranges will never be
|
||||
// exposed to content.
|
||||
mozilla::dom::AutoNoJSAPI nojsapi;
|
||||
|
||||
// Forward, not wrapping: SelEnd to DocEnd
|
||||
if (!mFindBackwards && !aWrap) {
|
||||
// This isn't quite right, since the selection's ranges aren't
|
||||
|
|
Загрузка…
Ссылка в новой задаче