Bug 1304634 - Part 1: Introduce MarkAsAutofillField API and necessary logic changes in controller, r=MattN

MozReview-Commit-ID: BeZXuWMvcQg

--HG--
extra : rebase_source : b4d9f774e5aca4a1520a685bfaa1f3b68e86c0d3
This commit is contained in:
Matthew Noorenberghe 2016-09-22 15:26:28 +08:00
parent fd819ff921
commit 9b47622cca
3 changed files with 38 additions and 1 deletions

View File

@ -206,6 +206,7 @@ void
nsFormFillController::NodeWillBeDestroyed(const nsINode* aNode)
{
mPwmgrInputs.Remove(aNode);
mAutofillInputs.Remove(aNode);
if (aNode == mListNode) {
mListNode = nullptr;
RevalidateDataList();
@ -220,7 +221,7 @@ nsFormFillController::MaybeRemoveMutationObserver(nsINode* aNode)
{
// Nodes being tracked in mPwmgrInputs will have their observers removed when
// they stop being tracked.
if (!mPwmgrInputs.Get(aNode)) {
if (!mPwmgrInputs.Get(aNode) && !mAutofillInputs.Get(aNode)) {
aNode->RemoveMutationObserver(this);
}
}
@ -294,6 +295,21 @@ nsFormFillController::MarkAsLoginManagerField(nsIDOMHTMLInputElement *aInput)
return NS_OK;
}
NS_IMETHODIMP
nsFormFillController::MarkAsAutofillField(nsIDOMHTMLInputElement *aInput)
{
/*
* Support other components implementing form autofill and handle autocomplete
* for the field.
*/
nsCOMPtr<nsINode> node = do_QueryInterface(aInput);
NS_ENSURE_STATE(node);
mAutofillInputs.Put(node, true);
node->AddMutationObserverUnlessExists(this);
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
//// nsIAutoCompleteInput
@ -908,6 +924,18 @@ nsFormFillController::RemoveForDocument(nsIDocument* aDoc)
iter.Remove();
}
}
for (auto iter = mAutofillInputs.Iter(); !iter.Done(); iter.Next()) {
const nsINode* key = iter.Key();
if (key && (!aDoc || key->OwnerDoc() == aDoc)) {
// mFocusedInputNode's observer is tracked separately, so don't remove it
// here.
if (key != mFocusedInputNode) {
const_cast<nsINode*>(key)->RemoveMutationObserver(this);
}
iter.Remove();
}
}
}
void

View File

@ -111,6 +111,7 @@ protected:
nsString mLastSearchString;
nsDataHashtable<nsPtrHashKey<const nsINode>, bool> mPwmgrInputs;
nsDataHashtable<nsPtrHashKey<const nsINode>, bool> mAutofillInputs;
uint32_t mTimeout;
uint32_t mMinResultsForPopup;

View File

@ -43,4 +43,12 @@ interface nsIFormFillController : nsISupports
* @param aInput - The HTML <input> element to tag
*/
void markAsLoginManagerField(in nsIDOMHTMLInputElement aInput);
/*
* Mark the specified <input> element as being managed by a form autofill component.
* Autocomplete requests will be handed off to the autofill component.
*
* @param aInput - The HTML <input> element to mark
*/
void markAsAutofillField(in nsIDOMHTMLInputElement aInput);
};