Bug 1685303: part 10) Annotate nsFrameSelection::HandleClick with MOZ_CAN_RUN_SCRIPT. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D101598
This commit is contained in:
Mirko Brodesser 2021-01-14 13:24:36 +00:00
parent 31e33f4d2c
commit c0d32bffc5
11 changed files with 52 additions and 33 deletions

View File

@ -258,6 +258,7 @@ interface nsISelectionController : nsISelectionDisplay
* @param aForward forward or backward if PR_FALSE
* @param aExtend should it collapse the selection of extend it?
*/
[can_run_script]
void completeMove(in boolean forward, in boolean extend);

View File

@ -340,12 +340,14 @@ class TextInputSelectionController final : public nsSupportsWeakReference,
bool aExtend) override;
NS_IMETHOD CharacterMove(bool aForward, bool aExtend) override;
NS_IMETHOD WordMove(bool aForward, bool aExtend) override;
NS_IMETHOD LineMove(bool aForward, bool aExtend) override;
MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHOD LineMove(bool aForward,
bool aExtend) override;
NS_IMETHOD IntraLineMove(bool aForward, bool aExtend) override;
MOZ_CAN_RUN_SCRIPT
NS_IMETHOD PageMove(bool aForward, bool aExtend) override;
NS_IMETHOD CompleteScroll(bool aForward) override;
NS_IMETHOD CompleteMove(bool aForward, bool aExtend) override;
MOZ_CAN_RUN_SCRIPT NS_IMETHOD CompleteMove(bool aForward,
bool aExtend) override;
NS_IMETHOD ScrollPage(bool aForward) override;
NS_IMETHOD ScrollLine(bool aForward) override;
NS_IMETHOD ScrollCharacter(bool aRight) override;
@ -699,10 +701,11 @@ TextInputSelectionController::CompleteMove(bool aForward, bool aExtend) {
}
}
const RefPtr<nsIContent> pinnedParentDIV{parentDIV};
const nsFrameSelection::FocusMode focusMode =
aExtend ? nsFrameSelection::FocusMode::kExtendSelection
: nsFrameSelection::FocusMode::kCollapseToNewPoint;
frameSelection->HandleClick(parentDIV, offset, offset, focusMode, hint);
frameSelection->HandleClick(pinnedParentDIV, offset, offset, focusMode, hint);
// if we got this far, attempt to scroll no matter what the above result is
return CompleteScroll(aForward);

View File

@ -19,6 +19,7 @@
#include "mozilla/IMEStateManager.h"
#include "mozilla/IntegerPrintfMacros.h"
#include "mozilla/PresShell.h"
#include "mozilla/StaticAnalysisFunctions.h"
#include "mozilla/StaticPrefs_layout.h"
#include "nsCaret.h"
#include "nsContainerFrame.h"
@ -631,7 +632,8 @@ nsresult AccessibleCaretManager::SelectWordOrShortcut(const nsPoint& aPoint) {
if (theFrame && theFrame != ptFrame) {
SetSelectionDragState(true);
frameSelection->HandleClick(
offsets.content, offsets.StartOffset(), offsets.EndOffset(),
MOZ_KnownLive(offsets.content) /* bug 1636889 */,
offsets.StartOffset(), offsets.EndOffset(),
nsFrameSelection::FocusMode::kCollapseToNewPoint,
offsets.associate);
SetSelectionDragState(false);
@ -1251,8 +1253,9 @@ nsresult AccessibleCaretManager::DragCaretInternal(const nsPoint& aPoint) {
(GetCaretMode() == CaretMode::Selection)
? nsFrameSelection::FocusMode::kExtendSelection
: nsFrameSelection::FocusMode::kCollapseToNewPoint;
fs->HandleClick(offsets.content, offsets.StartOffset(), offsets.EndOffset(),
focusMode, offsets.associate);
fs->HandleClick(MOZ_KnownLive(offsets.content) /* bug 1636889 */,
offsets.StartOffset(), offsets.EndOffset(), focusMode,
offsets.associate);
return NS_OK;
}

View File

@ -30,6 +30,7 @@
#include "mozilla/RangeUtils.h"
#include "mozilla/ScopeExit.h"
#include "mozilla/Sprintf.h"
#include "mozilla/StaticAnalysisFunctions.h"
#include "mozilla/StaticPrefs_apz.h"
#include "mozilla/StaticPrefs_dom.h"
#include "mozilla/StaticPrefs_font.h"
@ -2467,7 +2468,8 @@ PresShell::CompleteMove(bool aForward, bool aExtend) {
aExtend ? nsFrameSelection::FocusMode::kExtendSelection
: nsFrameSelection::FocusMode::kCollapseToNewPoint;
frameSelection->HandleClick(
pos.mResultContent, pos.mContentOffset, pos.mContentOffset, focusMode,
MOZ_KnownLive(pos.mResultContent) /* bug 1636889 */, pos.mContentOffset,
pos.mContentOffset, focusMode,
aForward ? CARET_ASSOCIATE_AFTER : CARET_ASSOCIATE_BEFORE);
if (limiter) {
// HandleClick resets ancestorLimiter, so set it again.

View File

@ -1319,8 +1319,10 @@ class PresShell final : public nsStubDocumentObserver,
NS_IMETHOD PhysicalMove(int16_t aDirection, int16_t aAmount,
bool aExtend) override;
NS_IMETHOD CharacterMove(bool aForward, bool aExtend) override;
NS_IMETHOD WordMove(bool aForward, bool aExtend) override;
NS_IMETHOD LineMove(bool aForward, bool aExtend) override;
MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHOD WordMove(bool aForward,
bool aExtend) override;
MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHOD LineMove(bool aForward,
bool aExtend) override;
NS_IMETHOD IntraLineMove(bool aForward, bool aExtend) override;
MOZ_CAN_RUN_SCRIPT
NS_IMETHOD PageMove(bool aForward, bool aExtend) override;
@ -1328,7 +1330,8 @@ class PresShell final : public nsStubDocumentObserver,
NS_IMETHOD ScrollLine(bool aForward) override;
NS_IMETHOD ScrollCharacter(bool aRight) override;
NS_IMETHOD CompleteScroll(bool aForward) override;
NS_IMETHOD CompleteMove(bool aForward, bool aExtend) override;
MOZ_CAN_RUN_SCRIPT NS_IMETHOD CompleteMove(bool aForward,
bool aExtend) override;
NS_IMETHOD CheckVisibility(nsINode* node, int16_t startOffset,
int16_t EndOffset, bool* _retval) override;
nsresult CheckVisibilityContent(nsIContent* aNode, int16_t aStartOffset,

View File

@ -18,6 +18,7 @@
#include "mozilla/Logging.h"
#include "mozilla/PresShell.h"
#include "mozilla/ScrollTypes.h"
#include "mozilla/StaticAnalysisFunctions.h"
#include "mozilla/StaticPrefs_bidi.h"
#include "mozilla/StaticPrefs_dom.h"
#include "mozilla/StaticPrefs_layout.h"
@ -1317,8 +1318,8 @@ void nsFrameSelection::HandleDrag(nsIFrame* aFrame, const nsPoint& aPoint) {
mMaintainedRange.AdjustContentOffsets(offsets, scrollViewStop);
// TODO: no click has happened, rename `HandleClick`.
HandleClick(offsets.content, offsets.offset, offsets.offset,
FocusMode::kExtendSelection, offsets.associate);
HandleClick(MOZ_KnownLive(offsets.content) /* bug 1636889 */, offsets.offset,
offsets.offset, FocusMode::kExtendSelection, offsets.associate);
}
nsresult nsFrameSelection::StartAutoScrollTimer(nsIFrame* aFrame,
@ -1926,7 +1927,8 @@ nsresult nsFrameSelection::PageMove(bool aForward, bool aExtend,
const FocusMode focusMode =
aExtend ? FocusMode::kExtendSelection : FocusMode::kCollapseToNewPoint;
HandleClick(offsets.content, offsets.offset, offsets.offset, focusMode,
HandleClick(MOZ_KnownLive(offsets.content) /* bug 1636889 */,
offsets.offset, offsets.offset, focusMode,
CARET_ASSOCIATE_AFTER);
selectionChanged = selection->AnchorRef() != oldAnchor ||

View File

@ -239,11 +239,11 @@ class nsFrameSelection final {
* @param aHint will tell the selection which direction geometrically to
* actually show the caret on. 1 = end of this line 0 = beginning of this line
*/
MOZ_CAN_RUN_SCRIPT_BOUNDARY nsresult HandleClick(nsIContent* aNewFocus,
uint32_t aContentOffset,
uint32_t aContentEndOffset,
FocusMode aFocusMode,
CaretAssociateHint aHint);
MOZ_CAN_RUN_SCRIPT nsresult HandleClick(nsIContent* aNewFocus,
uint32_t aContentOffset,
uint32_t aContentEndOffset,
FocusMode aFocusMode,
CaretAssociateHint aHint);
/**
* HandleDrag extends the selection to contain the frame closest to aPoint.
@ -256,7 +256,6 @@ class nsFrameSelection final {
*
* @param aPoint is relative to aFrame
*/
// TODO: replace with `MOZ_CAN_RUN_SCRIPT`.
MOZ_CAN_RUN_SCRIPT void HandleDrag(nsIFrame* aFrame, const nsPoint& aPoint);
/**

View File

@ -27,6 +27,7 @@
#include "mozilla/PresShellInlines.h"
#include "mozilla/ResultExtensions.h"
#include "mozilla/Sprintf.h"
#include "mozilla/StaticAnalysisFunctions.h"
#include "mozilla/StaticPrefs_layout.h"
#include "mozilla/SVGMaskFrame.h"
#include "mozilla/SVGObserverUtils.h"
@ -4795,8 +4796,9 @@ nsIFrame::HandlePress(nsPresContext* aPresContext, WidgetGUIEvent* aEvent,
return nsFrameSelection::FocusMode::kCollapseToNewPoint;
}();
rv = fc->HandleClick(offsets.content, offsets.StartOffset(),
offsets.EndOffset(), focusMode, offsets.associate);
rv = fc->HandleClick(MOZ_KnownLive(offsets.content) /* bug 1636889 */,
offsets.StartOffset(), offsets.EndOffset(), focusMode,
offsets.associate);
if (NS_FAILED(rv)) return rv;
@ -4948,12 +4950,14 @@ nsresult nsIFrame::PeekBackwardAndForward(nsSelectionAmount aAmountBack,
? nsFrameSelection::FocusMode::kMultiRangeSelection
: nsFrameSelection::FocusMode::kCollapseToNewPoint;
rv = frameSelection->HandleClick(
startpos.mResultContent, startpos.mContentOffset, startpos.mContentOffset,
focusMode, CARET_ASSOCIATE_AFTER);
MOZ_KnownLive(startpos.mResultContent) /* bug 1636889 */,
startpos.mContentOffset, startpos.mContentOffset, focusMode,
CARET_ASSOCIATE_AFTER);
if (NS_FAILED(rv)) return rv;
rv = frameSelection->HandleClick(
endpos.mResultContent, endpos.mContentOffset, endpos.mContentOffset,
MOZ_KnownLive(endpos.mResultContent) /* bug 1636889 */,
endpos.mContentOffset, endpos.mContentOffset,
nsFrameSelection::FocusMode::kExtendSelection, CARET_ASSOCIATE_BEFORE);
if (NS_FAILED(rv)) return rv;
@ -5077,8 +5081,9 @@ MOZ_CAN_RUN_SCRIPT_BOUNDARY static nsresult HandleFrameSelection(
? nsFrameSelection::FocusMode::kExtendSelection
: nsFrameSelection::FocusMode::kCollapseToNewPoint;
rv = aFrameSelection->HandleClick(
aOffsets.content, aOffsets.StartOffset(), aOffsets.EndOffset(),
focusMode, aOffsets.associate);
MOZ_KnownLive(aOffsets.content) /* bug 1636889 */,
aOffsets.StartOffset(), aOffsets.EndOffset(), focusMode,
aOffsets.associate);
if (NS_FAILED(rv)) {
return rv;
}

View File

@ -2151,10 +2151,9 @@ class nsIFrame : public nsQueryFrame {
nsSelectionAmount aEndAmountType,
uint32_t aSelectFlags);
nsresult PeekBackwardAndForward(nsSelectionAmount aAmountBack,
nsSelectionAmount aAmountForward,
int32_t aStartPos, bool aJumpLines,
uint32_t aSelectFlags);
MOZ_CAN_RUN_SCRIPT_BOUNDARY nsresult PeekBackwardAndForward(
nsSelectionAmount aAmountBack, nsSelectionAmount aAmountForward,
int32_t aStartPos, bool aJumpLines, uint32_t aSelectFlags);
enum { SELECT_ACCUMULATE = 0x01 };

View File

@ -3578,7 +3578,7 @@ void SVGTextFrame::SelectSubString(nsIContent* aContent, uint32_t charnum,
return;
}
charnum = chit.TextElementCharIndex();
nsIContent* content = chit.TextFrame()->GetContent();
const RefPtr<nsIContent> content = chit.TextFrame()->GetContent();
chit.NextWithinSubtree(nchars);
nchars = chit.TextElementCharIndex() - charnum;

View File

@ -236,8 +236,10 @@ class SVGTextFrame final : public SVGDisplayContainerFrame {
// SVG DOM text methods:
uint32_t GetNumberOfChars(nsIContent* aContent);
float GetComputedTextLength(nsIContent* aContent);
void SelectSubString(nsIContent* aContent, uint32_t charnum, uint32_t nchars,
ErrorResult& aRv);
MOZ_CAN_RUN_SCRIPT_BOUNDARY void SelectSubString(nsIContent* aContent,
uint32_t charnum,
uint32_t nchars,
ErrorResult& aRv);
MOZ_CAN_RUN_SCRIPT
float GetSubStringLength(nsIContent* aContent, uint32_t charnum,
uint32_t nchars, ErrorResult& aRv);