mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-23 02:05:42 +00:00
Bug 1599971 - part 1: Mark constructors of AutoTextControlHandlingState
as MOZ_CAN_RUN_SCRIPT
r=m_kato
The destructor of `AutoTextControlHandlingState`is marked as `MOZ_CAN_RUN_SCRIPT`, but it's not checked at build time. And this does not need to be created when the method does not run script. Therefore, we should mark its constructor as `MOZ_CAN_RUN_SCRIPT` instead since it's stack only class so that its constructor and destructor are always called from same method. Differential Revision: https://phabricator.services.mozilla.com/D55772 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
5d374a9099
commit
a26ed4b301
@ -245,7 +245,7 @@ class HTMLInputElement final : public TextControlElement,
|
||||
virtual void InitializeKeyboardEventListeners() override;
|
||||
virtual void OnValueChanged(bool aNotify, ValueChangeKind) override;
|
||||
virtual void GetValueFromSetRangeText(nsAString& aValue) override;
|
||||
MOZ_CAN_RUN_SCRIPT_BOUNDARY virtual nsresult SetValueFromSetRangeText(
|
||||
MOZ_CAN_RUN_SCRIPT virtual nsresult SetValueFromSetRangeText(
|
||||
const nsAString& aValue) override;
|
||||
virtual bool HasCachedSelection() override;
|
||||
|
||||
@ -695,22 +695,28 @@ class HTMLInputElement final : public TextControlElement,
|
||||
void Select();
|
||||
|
||||
Nullable<uint32_t> GetSelectionStart(ErrorResult& aRv);
|
||||
void SetSelectionStart(const Nullable<uint32_t>& aValue, ErrorResult& aRv);
|
||||
MOZ_CAN_RUN_SCRIPT void SetSelectionStart(const Nullable<uint32_t>& aValue,
|
||||
ErrorResult& aRv);
|
||||
|
||||
Nullable<uint32_t> GetSelectionEnd(ErrorResult& aRv);
|
||||
void SetSelectionEnd(const Nullable<uint32_t>& aValue, ErrorResult& aRv);
|
||||
MOZ_CAN_RUN_SCRIPT void SetSelectionEnd(const Nullable<uint32_t>& aValue,
|
||||
ErrorResult& aRv);
|
||||
|
||||
void GetSelectionDirection(nsAString& aValue, ErrorResult& aRv);
|
||||
void SetSelectionDirection(const nsAString& aValue, ErrorResult& aRv);
|
||||
MOZ_CAN_RUN_SCRIPT void SetSelectionDirection(const nsAString& aValue,
|
||||
ErrorResult& aRv);
|
||||
|
||||
void SetSelectionRange(uint32_t aStart, uint32_t aEnd,
|
||||
const Optional<nsAString>& direction,
|
||||
ErrorResult& aRv);
|
||||
MOZ_CAN_RUN_SCRIPT void SetSelectionRange(
|
||||
uint32_t aStart, uint32_t aEnd, const Optional<nsAString>& direction,
|
||||
ErrorResult& aRv);
|
||||
|
||||
void SetRangeText(const nsAString& aReplacement, ErrorResult& aRv);
|
||||
MOZ_CAN_RUN_SCRIPT void SetRangeText(const nsAString& aReplacement,
|
||||
ErrorResult& aRv);
|
||||
|
||||
void SetRangeText(const nsAString& aReplacement, uint32_t aStart,
|
||||
uint32_t aEnd, SelectionMode aSelectMode, ErrorResult& aRv);
|
||||
MOZ_CAN_RUN_SCRIPT void SetRangeText(const nsAString& aReplacement,
|
||||
uint32_t aStart, uint32_t aEnd,
|
||||
SelectionMode aSelectMode,
|
||||
ErrorResult& aRv);
|
||||
|
||||
bool Allowdirs() const {
|
||||
return HasAttr(kNameSpaceID_None, nsGkAtoms::allowdirs);
|
||||
|
@ -101,8 +101,8 @@ class HTMLTextAreaElement final : public TextControlElement,
|
||||
virtual void InitializeKeyboardEventListeners() override;
|
||||
virtual void OnValueChanged(bool aNotify, ValueChangeKind) override;
|
||||
virtual void GetValueFromSetRangeText(nsAString& aValue) override;
|
||||
MOZ_CAN_RUN_SCRIPT_BOUNDARY
|
||||
virtual nsresult SetValueFromSetRangeText(const nsAString& aValue) override;
|
||||
MOZ_CAN_RUN_SCRIPT virtual nsresult SetValueFromSetRangeText(
|
||||
const nsAString& aValue) override;
|
||||
virtual bool HasCachedSelection() override;
|
||||
|
||||
// nsIContent
|
||||
@ -214,10 +214,13 @@ class HTMLTextAreaElement final : public TextControlElement,
|
||||
}
|
||||
bool Required() const { return State().HasState(NS_EVENT_STATE_REQUIRED); }
|
||||
|
||||
void SetRangeText(const nsAString& aReplacement, ErrorResult& aRv);
|
||||
MOZ_CAN_RUN_SCRIPT void SetRangeText(const nsAString& aReplacement,
|
||||
ErrorResult& aRv);
|
||||
|
||||
void SetRangeText(const nsAString& aReplacement, uint32_t aStart,
|
||||
uint32_t aEnd, SelectionMode aSelectMode, ErrorResult& aRv);
|
||||
MOZ_CAN_RUN_SCRIPT void SetRangeText(const nsAString& aReplacement,
|
||||
uint32_t aStart, uint32_t aEnd,
|
||||
SelectionMode aSelectMode,
|
||||
ErrorResult& aRv);
|
||||
|
||||
void SetRequired(bool aRequired, ErrorResult& aError) {
|
||||
SetHTMLBoolAttr(nsGkAtoms::required, aRequired, aError);
|
||||
@ -243,8 +246,8 @@ class HTMLTextAreaElement final : public TextControlElement,
|
||||
* nsContentUtils::PlatformToDOMLineBreaks().
|
||||
*/
|
||||
bool ValueEquals(const nsAString& aValue) const;
|
||||
MOZ_CAN_RUN_SCRIPT_BOUNDARY
|
||||
void SetValue(const nsAString& aValue, ErrorResult& aError);
|
||||
MOZ_CAN_RUN_SCRIPT_BOUNDARY void SetValue(const nsAString& aValue,
|
||||
ErrorResult& aError);
|
||||
|
||||
uint32_t GetTextLength();
|
||||
|
||||
@ -254,16 +257,17 @@ class HTMLTextAreaElement final : public TextControlElement,
|
||||
|
||||
void Select();
|
||||
Nullable<uint32_t> GetSelectionStart(ErrorResult& aError);
|
||||
void SetSelectionStart(const Nullable<uint32_t>& aSelectionStart,
|
||||
ErrorResult& aError);
|
||||
MOZ_CAN_RUN_SCRIPT void SetSelectionStart(
|
||||
const Nullable<uint32_t>& aSelectionStart, ErrorResult& aError);
|
||||
Nullable<uint32_t> GetSelectionEnd(ErrorResult& aError);
|
||||
void SetSelectionEnd(const Nullable<uint32_t>& aSelectionEnd,
|
||||
ErrorResult& aError);
|
||||
MOZ_CAN_RUN_SCRIPT void SetSelectionEnd(
|
||||
const Nullable<uint32_t>& aSelectionEnd, ErrorResult& aError);
|
||||
void GetSelectionDirection(nsAString& aDirection, ErrorResult& aError);
|
||||
void SetSelectionDirection(const nsAString& aDirection, ErrorResult& aError);
|
||||
void SetSelectionRange(uint32_t aSelectionStart, uint32_t aSelectionEnd,
|
||||
const Optional<nsAString>& aDirecton,
|
||||
ErrorResult& aError);
|
||||
MOZ_CAN_RUN_SCRIPT void SetSelectionDirection(const nsAString& aDirection,
|
||||
ErrorResult& aError);
|
||||
MOZ_CAN_RUN_SCRIPT void SetSelectionRange(
|
||||
uint32_t aSelectionStart, uint32_t aSelectionEnd,
|
||||
const Optional<nsAString>& aDirecton, ErrorResult& aError);
|
||||
nsIControllers* GetControllers(ErrorResult& aError);
|
||||
// XPCOM adapter function widely used throughout code, leaving it as is.
|
||||
nsresult GetControllers(nsIControllers** aResult);
|
||||
@ -275,8 +279,8 @@ class HTMLTextAreaElement final : public TextControlElement,
|
||||
|
||||
bool IsInputEventTarget() const { return true; }
|
||||
|
||||
MOZ_CAN_RUN_SCRIPT_BOUNDARY
|
||||
void SetUserInput(const nsAString& aValue, nsIPrincipal& aSubjectPrincipal);
|
||||
MOZ_CAN_RUN_SCRIPT_BOUNDARY void SetUserInput(
|
||||
const nsAString& aValue, nsIPrincipal& aSubjectPrincipal);
|
||||
|
||||
protected:
|
||||
virtual ~HTMLTextAreaElement();
|
||||
|
@ -199,7 +199,8 @@ class TextControlElement : public nsGenericHTMLFormElementWithState {
|
||||
* Helpers for value manipulation from SetRangeText.
|
||||
*/
|
||||
virtual void GetValueFromSetRangeText(nsAString& aValue) = 0;
|
||||
virtual nsresult SetValueFromSetRangeText(const nsAString& aValue) = 0;
|
||||
MOZ_CAN_RUN_SCRIPT virtual nsresult SetValueFromSetRangeText(
|
||||
const nsAString& aValue) = 0;
|
||||
|
||||
static const int32_t DEFAULT_COLS = 20;
|
||||
static const int32_t DEFAULT_ROWS = 1;
|
||||
|
@ -1073,10 +1073,11 @@ nsresult TextInputListener::UpdateTextInputCommands(
|
||||
*****************************************************************************/
|
||||
|
||||
enum class TextControlAction {
|
||||
PrepareEditor,
|
||||
CommitComposition,
|
||||
SetValue,
|
||||
PrepareEditor,
|
||||
SetRangeText,
|
||||
SetSelectionRange,
|
||||
SetValue,
|
||||
};
|
||||
|
||||
class MOZ_STACK_CLASS AutoTextControlHandlingState {
|
||||
@ -1092,8 +1093,8 @@ class MOZ_STACK_CLASS AutoTextControlHandlingState {
|
||||
* Generic constructor. If TextControlAction does not require additional
|
||||
* data, must use this constructor.
|
||||
*/
|
||||
AutoTextControlHandlingState(TextControlState& aTextControlState,
|
||||
TextControlAction aTextControlAction)
|
||||
MOZ_CAN_RUN_SCRIPT AutoTextControlHandlingState(
|
||||
TextControlState& aTextControlState, TextControlAction aTextControlAction)
|
||||
: mParent(aTextControlState.mHandlingState),
|
||||
mTextControlState(aTextControlState),
|
||||
mTextCtrlElement(aTextControlState.mTextCtrlElement),
|
||||
@ -1117,11 +1118,10 @@ class MOZ_STACK_CLASS AutoTextControlHandlingState {
|
||||
* must be specified and the creator should check whether we succeeded to
|
||||
* allocate memory for line breaker conversion.
|
||||
*/
|
||||
AutoTextControlHandlingState(TextControlState& aTextControlState,
|
||||
TextControlAction aTextControlAction,
|
||||
const nsAString& aSettingValue,
|
||||
const nsAString* aOldValue, uint32_t aFlags,
|
||||
ErrorResult& aRv)
|
||||
MOZ_CAN_RUN_SCRIPT AutoTextControlHandlingState(
|
||||
TextControlState& aTextControlState, TextControlAction aTextControlAction,
|
||||
const nsAString& aSettingValue, const nsAString* aOldValue,
|
||||
uint32_t aFlags, ErrorResult& aRv)
|
||||
: mParent(aTextControlState.mHandlingState),
|
||||
mTextControlState(aTextControlState),
|
||||
mTextCtrlElement(aTextControlState.mTextCtrlElement),
|
||||
@ -2113,6 +2113,7 @@ void TextControlState::SetSelectionStart(const Nullable<uint32_t>& aStart,
|
||||
}
|
||||
|
||||
SetSelectionRange(start, end, dir, aRv);
|
||||
// The instance may have already been deleted here.
|
||||
}
|
||||
|
||||
void TextControlState::SetSelectionEnd(const Nullable<uint32_t>& aEnd,
|
||||
@ -2134,6 +2135,7 @@ void TextControlState::SetSelectionEnd(const Nullable<uint32_t>& aEnd,
|
||||
}
|
||||
|
||||
SetSelectionRange(start, end, dir, aRv);
|
||||
// The instance may have already been deleted here.
|
||||
}
|
||||
|
||||
static void DirectionToName(nsITextControlFrame::SelectionDirection dir,
|
||||
@ -2192,6 +2194,7 @@ void TextControlState::SetSelectionDirection(const nsAString& aDirection,
|
||||
}
|
||||
|
||||
SetSelectionRange(start, end, dir, aRv);
|
||||
// The instance may have already been deleted here.
|
||||
}
|
||||
|
||||
static nsITextControlFrame::SelectionDirection
|
||||
@ -2212,6 +2215,7 @@ void TextControlState::SetSelectionRange(uint32_t aSelectionStart,
|
||||
DirectionStringToSelectionDirection(aDirection);
|
||||
|
||||
SetSelectionRange(aSelectionStart, aSelectionEnd, dir, aRv);
|
||||
// The instance may have already been deleted here.
|
||||
}
|
||||
|
||||
void TextControlState::SetRangeText(const nsAString& aReplacement,
|
||||
@ -2224,6 +2228,7 @@ void TextControlState::SetRangeText(const nsAString& aReplacement,
|
||||
|
||||
SetRangeText(aReplacement, start, end, SelectionMode::Preserve, aRv,
|
||||
Some(start), Some(end));
|
||||
// The instance may have already been deleted here.
|
||||
}
|
||||
|
||||
void TextControlState::SetRangeText(const nsAString& aReplacement,
|
||||
@ -2236,6 +2241,9 @@ void TextControlState::SetRangeText(const nsAString& aReplacement,
|
||||
return;
|
||||
}
|
||||
|
||||
AutoTextControlHandlingState handlingSetRangeText(
|
||||
*this, TextControlAction::SetRangeText);
|
||||
|
||||
nsAutoString value;
|
||||
mTextCtrlElement->GetValueFromSetRangeText(value);
|
||||
uint32_t inputValueLength = value.Length();
|
||||
@ -2263,7 +2271,8 @@ void TextControlState::SetRangeText(const nsAString& aReplacement,
|
||||
|
||||
MOZ_ASSERT(aStart <= aEnd);
|
||||
value.Replace(aStart, aEnd - aStart, aReplacement);
|
||||
nsresult rv = mTextCtrlElement->SetValueFromSetRangeText(value);
|
||||
nsresult rv =
|
||||
MOZ_KnownLive(mTextCtrlElement)->SetValueFromSetRangeText(value);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
return;
|
||||
@ -2301,6 +2310,7 @@ void TextControlState::SetRangeText(const nsAString& aReplacement,
|
||||
}
|
||||
|
||||
SetSelectionRange(selectionStart, selectionEnd, Optional<nsAString>(), aRv);
|
||||
// The instance may have already been deleted here.
|
||||
}
|
||||
|
||||
HTMLInputElement* TextControlState::GetParentNumberControl(
|
||||
|
@ -141,7 +141,9 @@ class TextControlState final : public SupportsWeakPtr<TextControlState> {
|
||||
|
||||
static TextControlState* Construct(TextControlElement* aOwningElement);
|
||||
|
||||
static void Shutdown();
|
||||
// Note that this does not run script actually because of `sHasShutDown`
|
||||
// is set to true before calling `DeleteOrCacheForReuse()`.
|
||||
MOZ_CAN_RUN_SCRIPT_BOUNDARY static void Shutdown();
|
||||
|
||||
/**
|
||||
* Destroy() deletes the instance immediately or later.
|
||||
@ -350,27 +352,28 @@ class TextControlState final : public SupportsWeakPtr<TextControlState> {
|
||||
//
|
||||
// XXXbz This should really take uint32_t, but none of our guts (either the
|
||||
// frame or our cached selection state) work with uint32_t at the moment...
|
||||
void SetSelectionRange(uint32_t aStart, uint32_t aEnd,
|
||||
nsITextControlFrame::SelectionDirection aDirection,
|
||||
ErrorResult& aRv);
|
||||
MOZ_CAN_RUN_SCRIPT void SetSelectionRange(
|
||||
uint32_t aStart, uint32_t aEnd,
|
||||
nsITextControlFrame::SelectionDirection aDirection, ErrorResult& aRv);
|
||||
|
||||
// Set the selection range, but with an optional string for the direction.
|
||||
// This will convert aDirection to an nsITextControlFrame::SelectionDirection
|
||||
// and then call our other SetSelectionRange overload.
|
||||
void SetSelectionRange(uint32_t aSelectionStart, uint32_t aSelectionEnd,
|
||||
const dom::Optional<nsAString>& aDirection,
|
||||
ErrorResult& aRv);
|
||||
MOZ_CAN_RUN_SCRIPT void SetSelectionRange(
|
||||
uint32_t aSelectionStart, uint32_t aSelectionEnd,
|
||||
const dom::Optional<nsAString>& aDirection, ErrorResult& aRv);
|
||||
|
||||
// Set the selection start. This basically implements the
|
||||
// https://html.spec.whatwg.org/multipage/forms.html#dom-textarea/input-selectionstart
|
||||
// setter.
|
||||
void SetSelectionStart(const dom::Nullable<uint32_t>& aStart,
|
||||
ErrorResult& aRv);
|
||||
MOZ_CAN_RUN_SCRIPT void SetSelectionStart(
|
||||
const dom::Nullable<uint32_t>& aStart, ErrorResult& aRv);
|
||||
|
||||
// Set the selection end. This basically implements the
|
||||
// https://html.spec.whatwg.org/multipage/forms.html#dom-textarea/input-selectionend
|
||||
// setter.
|
||||
void SetSelectionEnd(const dom::Nullable<uint32_t>& aEnd, ErrorResult& aRv);
|
||||
MOZ_CAN_RUN_SCRIPT void SetSelectionEnd(const dom::Nullable<uint32_t>& aEnd,
|
||||
ErrorResult& aRv);
|
||||
|
||||
// Get the selection direction as a string. This implements the
|
||||
// https://html.spec.whatwg.org/multipage/forms.html#dom-textarea/input-selectiondirection
|
||||
@ -380,18 +383,20 @@ class TextControlState final : public SupportsWeakPtr<TextControlState> {
|
||||
// Set the selection direction. This basically implements the
|
||||
// https://html.spec.whatwg.org/multipage/forms.html#dom-textarea/input-selectiondirection
|
||||
// setter.
|
||||
void SetSelectionDirection(const nsAString& aDirection, ErrorResult& aRv);
|
||||
MOZ_CAN_RUN_SCRIPT void SetSelectionDirection(const nsAString& aDirection,
|
||||
ErrorResult& aRv);
|
||||
|
||||
// Set the range text. This basically implements
|
||||
// https://html.spec.whatwg.org/multipage/forms.html#dom-textarea/input-setrangetext
|
||||
void SetRangeText(const nsAString& aReplacement, ErrorResult& aRv);
|
||||
MOZ_CAN_RUN_SCRIPT void SetRangeText(const nsAString& aReplacement,
|
||||
ErrorResult& aRv);
|
||||
// The last two arguments are -1 if we don't know our selection range;
|
||||
// otherwise they're the start and end of our selection range.
|
||||
void SetRangeText(const nsAString& aReplacement, uint32_t aStart,
|
||||
uint32_t aEnd, dom::SelectionMode aSelectMode,
|
||||
ErrorResult& aRv,
|
||||
const Maybe<uint32_t>& aSelectionStart = Nothing(),
|
||||
const Maybe<uint32_t>& aSelectionEnd = Nothing());
|
||||
MOZ_CAN_RUN_SCRIPT void SetRangeText(
|
||||
const nsAString& aReplacement, uint32_t aStart, uint32_t aEnd,
|
||||
dom::SelectionMode aSelectMode, ErrorResult& aRv,
|
||||
const Maybe<uint32_t>& aSelectionStart = Nothing(),
|
||||
const Maybe<uint32_t>& aSelectionEnd = Nothing());
|
||||
|
||||
void UpdateEditableState(bool aNotify) {
|
||||
if (auto* root = GetRootNode()) {
|
||||
|
@ -555,14 +555,15 @@ nsFormFillController::GetSelectionEnd(int32_t* aSelectionEnd) {
|
||||
return rv.StealNSResult();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHODIMP
|
||||
nsFormFillController::SelectTextRange(int32_t aStartIndex, int32_t aEndIndex) {
|
||||
if (!mFocusedInput) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
RefPtr<HTMLInputElement> focusedInput(mFocusedInput);
|
||||
ErrorResult rv;
|
||||
mFocusedInput->SetSelectionRange(aStartIndex, aEndIndex,
|
||||
Optional<nsAString>(), rv);
|
||||
focusedInput->SetSelectionRange(aStartIndex, aEndIndex, Optional<nsAString>(),
|
||||
rv);
|
||||
return rv.StealNSResult();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user