Skip to content

Commit

Permalink
Bug 1834006 part 2: Remove ATK specific password masking code. r=morgan
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jcsteh committed May 24, 2023
1 parent bfb493f commit 7f6ff0e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 69 deletions.
6 changes: 0 additions & 6 deletions accessible/atk/DOMtoATK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 5 additions & 24 deletions accessible/atk/DOMtoATK.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <glib.h>
#include <cstdint>
#include "mozilla/TypedEnumBits.h"
#include "mozilla/a11y/HyperTextAccessibleBase.h"
#include "nsCharTraits.h"
#include "nsString.h"

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -130,18 +114,15 @@ gchar* NewATKString(Accessible* aAccessible, gint aStartOffset, gint aEndOffset,
return g_strdup("");
}

if (aFlags & AtkStringConvertFlags::ConvertTextToAsterisks) {
ConvertTexttoAsterisks(str);
}
return converter.ConvertAdjusted(str);
}

/**
* 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));

Expand Down
47 changes: 8 additions & 39 deletions accessible/atk/nsMaiInterfaceText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 7f6ff0e

Please sign in to comment.