Bug 1834006 part 2: Remove ATK specific password masking code. r=morgan

The core, cross-platform implementation already masks passwords.
Thus, the ATK specific code has been unnecessary for a long time now.
The ATK masking code also only applied to LocalAccessible.
This means we can get rid of this differentiation between local and remote.

Differential Revision: https://phabricator.services.mozilla.com/D178610
This commit is contained in:
James Teh 2023-05-24 21:36:01 +00:00
parent bfb493f67d
commit 7f6ff0e384
3 changed files with 13 additions and 69 deletions

View File

@ -145,12 +145,6 @@ gchar* Convert(const nsAString& aStr) {
return g_strdup(cautoStrBOMs.get());
}
void ConvertTexttoAsterisks(nsAString& aString) {
for (uint32_t i = 0; i < aString.Length(); i++) {
aString.ReplaceLiteral(i, 1, u"*");
}
}
} // namespace DOMtoATK
} // namespace a11y

View File

@ -6,7 +6,7 @@
#include <glib.h>
#include <cstdint>
#include "mozilla/TypedEnumBits.h"
#include "mozilla/a11y/HyperTextAccessibleBase.h"
#include "nsCharTraits.h"
#include "nsString.h"
@ -57,21 +57,6 @@ gchar* Convert(const nsAString& aStr);
*/
void AddBOMs(nsACString& aDest, const nsACString& aSource);
/**
* Replace all characters with asterisks (e.g. for password fields).
*/
void ConvertTexttoAsterisks(nsAString& aString);
/**
* Parameterize conversion.
*/
enum class AtkStringConvertFlags : uint32_t {
None = 0,
ConvertTextToAsterisks = 1 << 0,
};
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(AtkStringConvertFlags)
class ATKStringConverterHelper {
public:
ATKStringConverterHelper(void)
@ -115,9 +100,8 @@ class ATKStringConverterHelper {
* Get text from aAccessible, using ATKStringConverterHelper to properly
* introduce appropriate BOMs.
*/
template <class Accessible>
gchar* NewATKString(Accessible* aAccessible, gint aStartOffset, gint aEndOffset,
AtkStringConvertFlags aFlags) {
inline gchar* NewATKString(HyperTextAccessibleBase* aAccessible,
gint aStartOffset, gint aEndOffset) {
gint startOffset = aStartOffset, endOffset = aEndOffset;
ATKStringConverterHelper converter;
converter.AdjustOffsets(&startOffset, &endOffset,
@ -130,9 +114,6 @@ gchar* NewATKString(Accessible* aAccessible, gint aStartOffset, gint aEndOffset,
return g_strdup("");
}
if (aFlags & AtkStringConvertFlags::ConvertTextToAsterisks) {
ConvertTexttoAsterisks(str);
}
return converter.ConvertAdjusted(str);
}
@ -140,8 +121,8 @@ gchar* NewATKString(Accessible* aAccessible, gint aStartOffset, gint aEndOffset,
* Get a character from aAccessible, fetching more data as appropriate to
* properly get non-BMP characters or a BOM as appropriate.
*/
template <class AccessibleCharAt>
gunichar ATKCharacter(AccessibleCharAt* aAccessible, gint aOffset) {
inline gunichar ATKCharacter(HyperTextAccessibleBase* aAccessible,
gint aOffset) {
// char16_t is unsigned short in Mozilla, gnuichar is guint32 in glib.
gunichar character = static_cast<gunichar>(aAccessible->CharAt(aOffset));

View File

@ -95,34 +95,18 @@ static AtkAttributeSet* ConvertToAtkTextAttributeSet(
return objAttributeSet;
}
static void ConvertTexttoAsterisks(Accessible* aAcc, nsAString& aString) {
// convert each char to "*" when it's "password text"
if (aAcc->IsPassword()) {
DOMtoATK::ConvertTexttoAsterisks(aString);
}
}
extern "C" {
static gchar* getTextCB(AtkText* aText, gint aStartOffset, gint aEndOffset) {
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
nsAutoString autoStr;
if (accWrap) {
HyperTextAccessible* text = accWrap->AsHyperText();
if (!text || !text->IsTextRole() || text->IsDefunct()) return nullptr;
return DOMtoATK::NewATKString(
text, aStartOffset, aEndOffset,
accWrap->IsPassword()
? DOMtoATK::AtkStringConvertFlags::ConvertTextToAsterisks
: DOMtoATK::AtkStringConvertFlags::None);
} else if (RemoteAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
return DOMtoATK::NewATKString(proxy, aStartOffset, aEndOffset,
DOMtoATK::AtkStringConvertFlags::None);
Accessible* acc = GetInternalObj(ATK_OBJECT(aText));
if (!acc || !acc->IsTextRole()) {
return nullptr;
}
return nullptr;
HyperTextAccessibleBase* text = acc->AsHyperTextBase();
if (!text) {
return nullptr;
}
return DOMtoATK::NewATKString(text, aStartOffset, aEndOffset);
}
static gint getCharacterCountCB(AtkText* aText);
@ -173,11 +157,6 @@ static gchar* getTextAfterOffsetCB(AtkText* aText, gint aOffset,
int32_t startOffset = 0, endOffset = 0;
text->TextAfterOffset(aOffset, aBoundaryType, &startOffset, &endOffset,
autoStr);
if (acc->IsLocal()) {
// XXX Is this needed any more? Masking of passwords is handled in
// cross-platform code.
ConvertTexttoAsterisks(acc, autoStr);
}
*aStartOffset = startOffset;
*aEndOffset = endOffset;
@ -206,11 +185,6 @@ static gchar* getTextAtOffsetCB(AtkText* aText, gint aOffset,
nsAutoString autoStr;
int32_t startOffset = 0, endOffset = 0;
text->TextAtOffset(aOffset, aBoundaryType, &startOffset, &endOffset, autoStr);
if (acc->IsLocal()) {
// XXX Is this needed any more? Masking of passwords is handled in
// cross-platform code.
ConvertTexttoAsterisks(acc, autoStr);
}
*aStartOffset = startOffset;
*aEndOffset = endOffset;
@ -254,11 +228,6 @@ static gchar* getTextBeforeOffsetCB(AtkText* aText, gint aOffset,
int32_t startOffset = 0, endOffset = 0;
text->TextBeforeOffset(aOffset, aBoundaryType, &startOffset, &endOffset,
autoStr);
if (acc->IsLocal()) {
// XXX Is this needed any more? Masking of passwords is handled in
// cross-platform code.
ConvertTexttoAsterisks(acc, autoStr);
}
*aStartOffset = startOffset;
*aEndOffset = endOffset;