Bug 1097452 - Use fallible allocation when setting the value of an <input> or <textarea> element; r=jst,froydnj
This patch handles most of the call sites for these allocations except for a few where I added TODO comments with some information. Handling those places may require reworking lots of code, so I prefer to not do that here.
This commit is contained in:
@@ -1397,7 +1397,8 @@ nsTextEditorState::PrepareEditor(const nsAString *aValue)
|
||||
rv = newEditor->EnableUndo(false);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
SetValue(defaultValue, false, false);
|
||||
bool success = SetValue(defaultValue, false, false);
|
||||
NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
rv = newEditor->EnableUndo(true);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv),"Transaction Manager must have failed");
|
||||
@@ -1655,7 +1656,9 @@ nsTextEditorState::UnbindFromFrame(nsTextControlFrame* aFrame)
|
||||
// Now that we don't have a frame any more, store the value in the text buffer.
|
||||
// The only case where we don't do this is if a value transfer is in progress.
|
||||
if (!mValueTransferInProgress) {
|
||||
SetValue(value, false, false);
|
||||
bool success = SetValue(value, false, false);
|
||||
// TODO Find something better to do if this fails...
|
||||
NS_ENSURE_TRUE_VOID(success);
|
||||
}
|
||||
|
||||
if (mRootNode && mMutationObserver) {
|
||||
@@ -1868,10 +1871,12 @@ nsTextEditorState::GetValue(nsAString& aValue, bool aIgnoreWrap) const
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
nsTextEditorState::SetValue(const nsAString& aValue, bool aUserInput,
|
||||
bool aSetValueChanged)
|
||||
{
|
||||
mozilla::fallible_t fallible;
|
||||
|
||||
if (mEditor && mBoundFrame) {
|
||||
// The InsertText call below might flush pending notifications, which
|
||||
// could lead into a scheduled PrepareEditor to be called. That will
|
||||
@@ -1901,16 +1906,21 @@ nsTextEditorState::SetValue(const nsAString& aValue, bool aUserInput,
|
||||
// so convert windows and mac platform linebreaks to \n:
|
||||
// Unfortunately aValue is declared const, so we have to copy
|
||||
// in order to do this substitution.
|
||||
nsString newValue(aValue);
|
||||
nsString newValue;
|
||||
if (!newValue.Assign(aValue, fallible)) {
|
||||
return false;
|
||||
}
|
||||
if (aValue.FindChar(char16_t('\r')) != -1) {
|
||||
nsContentUtils::PlatformToDOMLineBreaks(newValue);
|
||||
if (!nsContentUtils::PlatformToDOMLineBreaks(newValue, fallible)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> domDoc;
|
||||
mEditor->GetDocument(getter_AddRefs(domDoc));
|
||||
if (!domDoc) {
|
||||
NS_WARNING("Why don't we have a document?");
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Time to mess with our security context... See comments in GetValue()
|
||||
@@ -1947,7 +1957,7 @@ nsTextEditorState::SetValue(const nsAString& aValue, bool aUserInput,
|
||||
nsCOMPtr<nsIPlaintextEditor> plaintextEditor = do_QueryInterface(mEditor);
|
||||
if (!plaintextEditor || !weakFrame.IsAlive()) {
|
||||
NS_WARNING("Somehow not a plaintext editor?");
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
valueSetter.Init();
|
||||
@@ -1986,13 +1996,15 @@ nsTextEditorState::SetValue(const nsAString& aValue, bool aUserInput,
|
||||
// the existing selection -- see bug 574558), in which case we don't
|
||||
// need to reset the value here.
|
||||
if (!mBoundFrame) {
|
||||
SetValue(newValue, false, aSetValueChanged);
|
||||
return SetValue(newValue, false, aSetValueChanged);
|
||||
}
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!IsSingleLineTextControl()) {
|
||||
mCachedValue = newValue;
|
||||
if (!mCachedValue.Assign(newValue, fallible)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
plaintextEditor->SetMaxTextLength(savedMaxLength);
|
||||
@@ -2005,9 +2017,16 @@ nsTextEditorState::SetValue(const nsAString& aValue, bool aUserInput,
|
||||
if (!mValue) {
|
||||
mValue = new nsCString;
|
||||
}
|
||||
nsString value(aValue);
|
||||
nsContentUtils::PlatformToDOMLineBreaks(value);
|
||||
CopyUTF16toUTF8(value, *mValue);
|
||||
nsString value;
|
||||
if (!value.Assign(aValue, fallible)) {
|
||||
return false;
|
||||
}
|
||||
if (!nsContentUtils::PlatformToDOMLineBreaks(value, fallible)) {
|
||||
return false;
|
||||
}
|
||||
if (!CopyUTF16toUTF8(value, *mValue, fallible)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Update the frame display if needed
|
||||
if (mBoundFrame) {
|
||||
@@ -2020,6 +2039,8 @@ nsTextEditorState::SetValue(const nsAString& aValue, bool aUserInput,
|
||||
ValueWasChanged(!!mRootNode);
|
||||
|
||||
mTextCtrlElement->OnValueChanged(!!mRootNode);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user