From 0595320f209f0de624f2e9d97cfd6fd0f0a7d090 Mon Sep 17 00:00:00 2001 From: Brad Lassey Date: Wed, 25 Nov 2009 12:41:23 -0500 Subject: [PATCH 1/3] bug 530367 - passwords from password manager flash in clear text r=neil --- editor/idl/nsIPlaintextEditor.idl | 1 + editor/libeditor/text/nsTextEditRules.cpp | 3 ++- layout/forms/nsTextControlFrame.cpp | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/editor/idl/nsIPlaintextEditor.idl b/editor/idl/nsIPlaintextEditor.idl index 750a644b9a1c..5f013ee7bfda 100644 --- a/editor/idl/nsIPlaintextEditor.idl +++ b/editor/idl/nsIPlaintextEditor.idl @@ -56,6 +56,7 @@ interface nsIPlaintextEditor : nsISupports const long eEditorWidgetMask = 0x0200; /* bit for widgets */ const long eEditorNoCSSMask = 0x0400; /* this HTML editor should not create css styles */ const long eEditorAllowInteraction = 0x0800; /* */ + const long eEditorDontEchoPassword = 0x1000; /* * The valid values for newlines handling. diff --git a/editor/libeditor/text/nsTextEditRules.cpp b/editor/libeditor/text/nsTextEditRules.cpp index f71741580ec2..d4042e6b5a70 100644 --- a/editor/libeditor/text/nsTextEditRules.cpp +++ b/editor/libeditor/text/nsTextEditRules.cpp @@ -672,7 +672,8 @@ nsTextEditRules::WillInsertText(PRInt32 aAction, mPasswordText.Insert(*outString, start); nsCOMPtr lookAndFeel = do_GetService(kLookAndFeelCID); - if (lookAndFeel->GetEchoPassword()) { + if (lookAndFeel->GetEchoPassword() && + !(mFlags & nsIPlaintextEditor::eEditorDontEchoPassword)) { if (mPasswordText.Length() > outString->Length()) { HideLastPWInput(); } diff --git a/layout/forms/nsTextControlFrame.cpp b/layout/forms/nsTextControlFrame.cpp index 9ea27527c3e7..25925c727e3a 100644 --- a/layout/forms/nsTextControlFrame.cpp +++ b/layout/forms/nsTextControlFrame.cpp @@ -2675,6 +2675,7 @@ nsTextControlFrame::SetValue(const nsAString& aValue) flags &= ~(nsIPlaintextEditor::eEditorDisabledMask); flags &= ~(nsIPlaintextEditor::eEditorReadonlyMask); flags |= nsIPlaintextEditor::eEditorUseAsyncUpdatesMask; + flags |= nsIPlaintextEditor::eEditorDontEchoPassword; editor->SetFlags(flags); // Also don't enforce max-length here From e66219b5539155ed3613779c21afff5bed2633fe Mon Sep 17 00:00:00 2001 From: Brad Lassey Date: Wed, 25 Nov 2009 12:50:35 -0500 Subject: [PATCH 2/3] bug 527674 - number of askterisks doesn't match the number of password charecters when user hits delete r=neil --- editor/libeditor/text/nsTextEditRules.cpp | 92 +++++++++++++++++------ 1 file changed, 67 insertions(+), 25 deletions(-) diff --git a/editor/libeditor/text/nsTextEditRules.cpp b/editor/libeditor/text/nsTextEditRules.cpp index d4042e6b5a70..0e1f2a6388dd 100644 --- a/editor/libeditor/text/nsTextEditRules.cpp +++ b/editor/libeditor/text/nsTextEditRules.cpp @@ -520,6 +520,38 @@ nsTextEditRules::DidInsertBreak(nsISelection *aSelection, nsresult aResult) return res; } +static inline already_AddRefed +GetTextNode(nsISelection *selection, nsEditor *editor) { + PRInt32 selOffset; + nsCOMPtr selNode; + nsresult res = editor->GetStartNodeAndOffset(selection, address_of(selNode), &selOffset); + if (NS_FAILED(res)) return nsnull; + if (!editor->IsTextNode(selNode)) { + // Get an nsINode from the nsIDOMNode + nsCOMPtr node = do_QueryInterface(selNode); + // if node is null, return it to indicate there's no text + if (!node) return nsnull; + // This should be the root node, walk the tree looking for text nodes + nsNodeIterator iter(node, nsIDOMNodeFilter::SHOW_TEXT, nsnull, PR_TRUE); + while (!editor->IsTextNode(selNode)) { + if (NS_FAILED(res = iter.NextNode(getter_AddRefs(selNode))) || !selNode) { + return nsnull; + } + } + } + return selNode.forget(); +} +#ifdef DEBUG +#define ASSERT_PASSWORD_LENGTHS_EQUAL() \ + if (mFlags & nsIPlaintextEditor::eEditorPasswordMask) { \ + PRInt32 txtLen; \ + mEditor->GetTextLength(&txtLen); \ + NS_ASSERTION(mPasswordText.Length() == txtLen, \ + "password length not equal to number of asterisks"); \ + } +#else +#define ASSERT_PASSWORD_LENGTHS_EQUAL() +#endif nsresult nsTextEditRules::WillInsertText(PRInt32 aAction, @@ -674,9 +706,7 @@ nsTextEditRules::WillInsertText(PRInt32 aAction, nsCOMPtr lookAndFeel = do_GetService(kLookAndFeelCID); if (lookAndFeel->GetEchoPassword() && !(mFlags & nsIPlaintextEditor::eEditorDontEchoPassword)) { - if (mPasswordText.Length() > outString->Length()) { - HideLastPWInput(); - } + HideLastPWInput(); mLastStart = start; mLastLength = outString->Length(); if (mTimer) @@ -863,6 +893,7 @@ nsTextEditRules::WillInsertText(PRInt32 aAction, selPrivate->SetInterlinePosition(endsWithLF); } } + ASSERT_PASSWORD_LENGTHS_EQUAL() return res; } @@ -943,6 +974,18 @@ nsTextEditRules::WillDeleteSelection(nsISelection *aSelection, PRUint32 start, end; mEditor->GetTextSelectionOffsets(aSelection, start, end); NS_ENSURE_SUCCESS(res, res); + nsCOMPtr lookAndFeel = do_GetService(kLookAndFeelCID); + + if (lookAndFeel->GetEchoPassword()) { + HideLastPWInput(); + mLastStart = start; + mLastLength = 0; + if (mTimer) + { + mTimer->Cancel(); + } + } + if (end == start) { // collapsed selection if (nsIEditor::ePrevious==aCollapsedAction && 0 selNode; + if (!mLastLength) { + // Special case, we're trying to replace a range that no longer exists + return NS_OK; + } + + nsAutoString hiddenText; + FillBufWithPWChars(&hiddenText, mLastLength); + nsCOMPtr selection; - PRInt32 selOffset; PRUint32 start, end; nsresult res = mEditor->GetSelection(getter_AddRefs(selection)); if (NS_FAILED(res)) return res; res = mEditor->GetTextSelectionOffsets(selection, start, end); if (NS_FAILED(res)) return res; - res = mEditor->GetStartNodeAndOffset(selection, address_of(selNode), &selOffset); - if (NS_FAILED(res)) return res; - if (!mEditor->IsTextNode(selNode)) { - // Get an nsINode from the nsIDOMNode - nsCOMPtr node = do_QueryInterface(selNode); - // if node is null, return NS_OK because there's no text to hide - if (!node) return NS_OK; - // This should be the root node, walk the tree looking for text nodes - nsNodeIterator iter(node, nsIDOMNodeFilter::SHOW_TEXT, nsnull, PR_TRUE); - while (!mEditor->IsTextNode(selNode)) { - if (NS_FAILED(res = iter.NextNode(getter_AddRefs(selNode))) || - selNode == nsnull) { - return NS_SUCCEEDED(res) ? NS_ERROR_NULL_POINTER : res; - } - } - } + + nsCOMPtr selNode = GetTextNode(selection, mEditor); + if (!selNode) + return NS_OK; + nsCOMPtr nodeAsText(do_QueryInterface(selNode)); - if (!nodeAsText) return NS_ERROR_FAILURE; - nsAutoString hiddenText; - FillBufWithPWChars(&hiddenText, mLastLength); + if (!nodeAsText) + return NS_OK; + nodeAsText->ReplaceData(mLastStart, mLastLength, hiddenText); selection->Collapse(selNode, start); if (start != end) From adf2498ce3cbfcdef69a801e0528c33f3367c78e Mon Sep 17 00:00:00 2001 From: "21@vingtetun.org" <21@vingtetun.org> Date: Wed, 25 Nov 2009 11:49:52 -0800 Subject: [PATCH 3/3] Bug 530495 - textbox.xml throw an error (line 175) if the textbox.inputField didn't exist (r=neil) --- toolkit/content/widgets/textbox.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/toolkit/content/widgets/textbox.xml b/toolkit/content/widgets/textbox.xml index 26be131890c3..2a95912f1a2f 100644 --- a/toolkit/content/widgets/textbox.xml +++ b/toolkit/content/widgets/textbox.xml @@ -171,9 +171,9 @@ // Hide the emptytext for a bit, in case the textbox will be focused subsequently this.inputField.setAttribute("emptytextdelay", "true"); - setTimeout(function (textbox) { - textbox.inputField.removeAttribute("emptytextdelay"); - }, 100, this); + setTimeout(function (input) { + input.removeAttribute("emptytextdelay"); + }, 100, this.inputField); try { this.editor.transactionManager.beginBatch();