2015-11-25 03:53:46 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2002-09-28 04:38:20 +04:00
|
|
|
|
|
|
|
#include "nsFormFillController.h"
|
|
|
|
|
2017-06-14 07:49:45 +03:00
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2017-03-09 22:44:03 +03:00
|
|
|
#include "mozilla/ErrorResult.h"
|
2018-02-08 16:42:29 +03:00
|
|
|
#include "mozilla/EventListenerManager.h"
|
2014-03-05 04:37:43 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2018-04-20 07:49:29 +03:00
|
|
|
#include "mozilla/dom/Event.h" // for Event
|
2016-11-15 20:46:32 +03:00
|
|
|
#include "mozilla/dom/HTMLInputElement.h"
|
2018-02-09 19:17:09 +03:00
|
|
|
#include "mozilla/dom/KeyboardEvent.h"
|
2018-02-09 19:17:09 +03:00
|
|
|
#include "mozilla/dom/KeyboardEventBinding.h"
|
2018-03-20 07:16:06 +03:00
|
|
|
#include "mozilla/dom/MouseEvent.h"
|
2017-07-21 23:32:48 +03:00
|
|
|
#include "mozilla/dom/PageTransitionEvent.h"
|
2017-07-22 01:32:18 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2009-06-20 00:19:18 +04:00
|
|
|
#include "nsIFormAutoComplete.h"
|
2010-09-10 09:19:20 +04:00
|
|
|
#include "nsIInputListAutoComplete.h"
|
2006-01-26 22:17:04 +03:00
|
|
|
#include "nsIAutoCompleteSimpleResult.h"
|
2002-09-28 04:38:20 +04:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIInterfaceRequestor.h"
|
2003-10-22 10:09:48 +04:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2002-09-28 04:38:20 +04:00
|
|
|
#include "nsIDocShellTreeItem.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsIWebNavigation.h"
|
|
|
|
#include "nsIContentViewer.h"
|
2004-12-01 01:54:13 +03:00
|
|
|
#include "nsIDocument.h"
|
2002-09-28 04:38:20 +04:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsRect.h"
|
2007-05-16 14:02:45 +04:00
|
|
|
#include "nsILoginManager.h"
|
2010-06-10 22:11:40 +04:00
|
|
|
#include "mozilla/ModuleUtils.h"
|
2006-01-25 23:23:24 +03:00
|
|
|
#include "nsToolkitCompsCID.h"
|
2006-08-27 01:42:54 +04:00
|
|
|
#include "nsEmbedCID.h"
|
2011-11-20 22:02:47 +04:00
|
|
|
#include "nsContentUtils.h"
|
2018-01-30 08:25:36 +03:00
|
|
|
#include "nsGenericHTMLElement.h"
|
2013-10-08 06:21:07 +04:00
|
|
|
#include "nsILoadContext.h"
|
2014-11-22 17:39:05 +03:00
|
|
|
#include "nsIFrame.h"
|
2016-05-31 13:59:41 +03:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
2016-12-01 03:01:52 +03:00
|
|
|
#include "nsFocusManager.h"
|
2013-04-20 02:18:33 +04:00
|
|
|
|
2017-02-10 14:45:26 +03:00
|
|
|
using namespace mozilla;
|
2013-04-20 02:18:33 +04:00
|
|
|
using namespace mozilla::dom;
|
2017-03-09 22:44:03 +03:00
|
|
|
using mozilla::ErrorResult;
|
2017-07-22 01:32:18 +03:00
|
|
|
using mozilla::LogLevel;
|
|
|
|
|
|
|
|
static mozilla::LazyLogModule sLogger("satchel");
|
2002-09-28 04:38:20 +04:00
|
|
|
|
2017-06-14 07:49:45 +03:00
|
|
|
static nsIFormAutoComplete*
|
|
|
|
GetFormAutoComplete()
|
|
|
|
{
|
|
|
|
static nsCOMPtr<nsIFormAutoComplete> sInstance;
|
|
|
|
static bool sInitialized = false;
|
|
|
|
if (!sInitialized) {
|
|
|
|
nsresult rv;
|
|
|
|
sInstance =
|
|
|
|
do_GetService("@mozilla.org/satchel/form-autocomplete;1",
|
|
|
|
&rv);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
ClearOnShutdown(&sInstance);
|
|
|
|
sInitialized = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sInstance;
|
|
|
|
}
|
|
|
|
|
2014-09-10 06:45:50 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION(nsFormFillController,
|
2017-12-14 05:11:45 +03:00
|
|
|
mController, mLoginManager, mLoginReputationService,
|
|
|
|
mFocusedPopup, mDocShells, mPopups, mLastListener,
|
|
|
|
mLastFormAutoComplete)
|
2014-09-10 06:45:50 +04:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsFormFillController)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIFormFillController)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIFormFillController)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIAutoCompleteInput)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIAutoCompleteSearch)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMEventListener)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIFormAutoCompleteObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIMutationObserver)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsFormFillController)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsFormFillController)
|
|
|
|
|
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
|
|
|
|
nsFormFillController::nsFormFillController() :
|
2012-07-30 18:20:58 +04:00
|
|
|
mFocusedInput(nullptr),
|
|
|
|
mListNode(nullptr),
|
2017-03-01 22:05:38 +03:00
|
|
|
// The amount of time a context menu event supresses showing a
|
|
|
|
// popup from a focus event in ms. This matches the threshold in
|
2017-02-10 14:45:26 +03:00
|
|
|
// toolkit/components/passwordmgr/LoginManagerContent.jsm.
|
2017-04-07 01:01:31 +03:00
|
|
|
mFocusAfterRightClickThreshold(400),
|
2002-09-28 04:38:20 +04:00
|
|
|
mTimeout(50),
|
|
|
|
mMinResultsForPopup(1),
|
2003-07-13 06:27:25 +04:00
|
|
|
mMaxRows(0),
|
2017-04-07 01:01:31 +03:00
|
|
|
mLastRightClickTimeStamp(TimeStamp()),
|
2011-10-17 18:59:28 +04:00
|
|
|
mDisableAutoComplete(false),
|
|
|
|
mCompleteDefaultIndex(false),
|
|
|
|
mCompleteSelectedIndex(false),
|
|
|
|
mForceComplete(false),
|
|
|
|
mSuppressOnInput(false)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
2006-01-01 02:34:46 +03:00
|
|
|
mController = do_GetService("@mozilla.org/autocomplete/controller;1");
|
2015-01-24 20:37:47 +03:00
|
|
|
MOZ_ASSERT(mController);
|
2002-09-28 04:38:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsFormFillController::~nsFormFillController()
|
|
|
|
{
|
2012-02-22 16:59:39 +04:00
|
|
|
if (mListNode) {
|
|
|
|
mListNode->RemoveMutationObserver(this);
|
2012-07-30 18:20:58 +04:00
|
|
|
mListNode = nullptr;
|
2012-02-22 16:59:39 +04:00
|
|
|
}
|
2018-01-30 08:25:36 +03:00
|
|
|
if (mFocusedInput) {
|
|
|
|
MaybeRemoveMutationObserver(mFocusedInput);
|
2012-07-30 18:20:58 +04:00
|
|
|
mFocusedInput = nullptr;
|
2012-02-22 16:59:39 +04:00
|
|
|
}
|
2015-11-25 03:53:46 +03:00
|
|
|
RemoveForDocument(nullptr);
|
2012-02-28 03:31:23 +04:00
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
// Remove ourselves as a focus listener from all cached docShells
|
2012-12-11 01:54:32 +04:00
|
|
|
uint32_t count = mDocShells.Length();
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> window = GetWindowForDocShell(mDocShells[i]);
|
2015-10-27 00:37:32 +03:00
|
|
|
RemoveWindowListeners(window);
|
2002-09-28 04:38:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-10 09:20:16 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
//// nsIMutationObserver
|
|
|
|
//
|
|
|
|
|
|
|
|
void
|
2018-03-01 14:36:58 +03:00
|
|
|
nsFormFillController::AttributeChanged(mozilla::dom::Element* aElement,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aNameSpaceID,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aAttribute, int32_t aModType,
|
2015-07-25 09:01:19 +03:00
|
|
|
const nsAttrValue* aOldValue)
|
2010-09-10 09:20:16 +04:00
|
|
|
{
|
2015-01-24 20:37:47 +03:00
|
|
|
if ((aAttribute == nsGkAtoms::type || aAttribute == nsGkAtoms::readonly ||
|
|
|
|
aAttribute == nsGkAtoms::autocomplete) &&
|
|
|
|
aNameSpaceID == kNameSpaceID_None) {
|
2018-01-30 08:25:36 +03:00
|
|
|
RefPtr<HTMLInputElement> focusedInput(mFocusedInput);
|
2015-01-24 20:37:47 +03:00
|
|
|
// Reset the current state of the controller, unconditionally.
|
|
|
|
StopControllingInput();
|
|
|
|
// Then restart based on the new values. We have to delay this
|
|
|
|
// to avoid ending up in an endless loop due to re-registering our
|
|
|
|
// mutation observer (which would notify us again for *this* event).
|
|
|
|
nsCOMPtr<nsIRunnable> event =
|
2018-01-30 08:25:36 +03:00
|
|
|
mozilla::NewRunnableMethod<RefPtr<HTMLInputElement>>(
|
2017-06-12 22:34:10 +03:00
|
|
|
"nsFormFillController::MaybeStartControllingInput",
|
|
|
|
this,
|
|
|
|
&nsFormFillController::MaybeStartControllingInput,
|
|
|
|
focusedInput);
|
2018-03-01 14:36:58 +03:00
|
|
|
aElement->OwnerDoc()->Dispatch(TaskCategory::Other, event.forget());
|
2015-01-24 20:37:47 +03:00
|
|
|
}
|
|
|
|
|
2012-02-22 16:59:39 +04:00
|
|
|
if (mListNode && mListNode->Contains(aElement)) {
|
|
|
|
RevalidateDataList();
|
|
|
|
}
|
2010-09-10 09:20:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-03-01 14:36:58 +03:00
|
|
|
nsFormFillController::ContentAppended(nsIContent* aChild)
|
2010-09-10 09:20:16 +04:00
|
|
|
{
|
2018-03-01 14:36:58 +03:00
|
|
|
if (mListNode && mListNode->Contains(aChild->GetParent())) {
|
2012-02-22 16:59:39 +04:00
|
|
|
RevalidateDataList();
|
|
|
|
}
|
2010-09-10 09:20:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-03-01 14:36:58 +03:00
|
|
|
nsFormFillController::ContentInserted(nsIContent* aChild)
|
2010-09-10 09:20:16 +04:00
|
|
|
{
|
2018-03-01 14:36:58 +03:00
|
|
|
if (mListNode && mListNode->Contains(aChild->GetParent())) {
|
2012-02-22 16:59:39 +04:00
|
|
|
RevalidateDataList();
|
|
|
|
}
|
2010-09-10 09:20:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-03-01 14:36:58 +03:00
|
|
|
nsFormFillController::ContentRemoved(nsIContent* aChild,
|
2010-09-10 09:20:16 +04:00
|
|
|
nsIContent* aPreviousSibling)
|
|
|
|
{
|
2018-03-01 14:36:58 +03:00
|
|
|
if (mListNode && mListNode->Contains(aChild->GetParent())) {
|
2012-02-22 16:59:39 +04:00
|
|
|
RevalidateDataList();
|
|
|
|
}
|
2010-09-10 09:20:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-03-01 14:36:58 +03:00
|
|
|
nsFormFillController::CharacterDataWillChange(nsIContent* aContent,
|
2018-02-27 17:30:27 +03:00
|
|
|
const CharacterDataChangeInfo&)
|
2010-09-10 09:20:16 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-03-01 14:36:58 +03:00
|
|
|
nsFormFillController::CharacterDataChanged(nsIContent* aContent,
|
2018-02-27 17:30:27 +03:00
|
|
|
const CharacterDataChangeInfo&)
|
2010-09-10 09:20:16 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-03-01 14:36:58 +03:00
|
|
|
nsFormFillController::AttributeWillChange(mozilla::dom::Element* aElement,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aNameSpaceID,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aAttribute, int32_t aModType,
|
2015-07-25 09:05:19 +03:00
|
|
|
const nsAttrValue* aNewValue)
|
2010-09-10 09:20:16 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-09-24 18:23:32 +03:00
|
|
|
void
|
2018-03-01 14:36:58 +03:00
|
|
|
nsFormFillController::NativeAnonymousChildListChange(nsIContent* aContent,
|
2015-09-24 18:23:32 +03:00
|
|
|
bool aIsRemove)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-09-10 09:20:16 +04:00
|
|
|
void
|
|
|
|
nsFormFillController::ParentChainChanged(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFormFillController::NodeWillBeDestroyed(const nsINode* aNode)
|
|
|
|
{
|
2017-07-22 01:32:18 +03:00
|
|
|
MOZ_LOG(sLogger, LogLevel::Verbose, ("NodeWillBeDestroyed: %p", aNode));
|
2012-02-22 16:59:39 +04:00
|
|
|
mPwmgrInputs.Remove(aNode);
|
2016-09-22 10:26:28 +03:00
|
|
|
mAutofillInputs.Remove(aNode);
|
2012-02-22 16:59:39 +04:00
|
|
|
if (aNode == mListNode) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mListNode = nullptr;
|
2012-02-22 16:59:39 +04:00
|
|
|
RevalidateDataList();
|
2018-01-30 08:25:36 +03:00
|
|
|
} else if (aNode == mFocusedInput) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mFocusedInput = nullptr;
|
2012-02-22 16:59:39 +04:00
|
|
|
}
|
2010-09-10 09:20:16 +04:00
|
|
|
}
|
|
|
|
|
2012-02-28 03:31:23 +04:00
|
|
|
void
|
|
|
|
nsFormFillController::MaybeRemoveMutationObserver(nsINode* aNode)
|
|
|
|
{
|
|
|
|
// Nodes being tracked in mPwmgrInputs will have their observers removed when
|
2016-11-03 13:07:39 +03:00
|
|
|
// they stop being tracked.
|
2016-09-22 10:26:28 +03:00
|
|
|
if (!mPwmgrInputs.Get(aNode) && !mAutofillInputs.Get(aNode)) {
|
2012-02-28 03:31:23 +04:00
|
|
|
aNode->RemoveMutationObserver(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
//// nsIFormFillController
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFormFillController::AttachToBrowser(nsIDocShell *aDocShell, nsIAutoCompletePopup *aPopup)
|
|
|
|
{
|
2017-07-22 01:32:18 +03:00
|
|
|
MOZ_LOG(sLogger, LogLevel::Debug,
|
|
|
|
("AttachToBrowser for docShell %p with popup %p", aDocShell, aPopup));
|
2002-09-28 04:38:20 +04:00
|
|
|
NS_ENSURE_TRUE(aDocShell && aPopup, NS_ERROR_ILLEGAL_VALUE);
|
2011-08-04 04:52:47 +04:00
|
|
|
|
2012-12-11 01:54:32 +04:00
|
|
|
mDocShells.AppendElement(aDocShell);
|
|
|
|
mPopups.AppendElement(aPopup);
|
2011-08-04 04:52:47 +04:00
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
// Listen for focus events on the domWindow of the docShell
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> window = GetWindowForDocShell(aDocShell);
|
2015-10-27 00:37:32 +03:00
|
|
|
AddWindowListeners(window);
|
2002-09-28 04:38:20 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFormFillController::DetachFromBrowser(nsIDocShell *aDocShell)
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t index = GetIndexOfDocShell(aDocShell);
|
2002-09-28 04:38:20 +04:00
|
|
|
NS_ENSURE_TRUE(index >= 0, NS_ERROR_FAILURE);
|
2011-08-04 04:52:47 +04:00
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
// Stop listening for focus events on the domWindow of the docShell
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> window =
|
2012-12-11 01:54:32 +04:00
|
|
|
GetWindowForDocShell(mDocShells.SafeElementAt(index));
|
2015-10-27 00:37:32 +03:00
|
|
|
RemoveWindowListeners(window);
|
2011-08-04 04:52:47 +04:00
|
|
|
|
2012-12-11 01:54:32 +04:00
|
|
|
mDocShells.RemoveElementAt(index);
|
|
|
|
mPopups.RemoveElementAt(index);
|
2011-08-04 04:52:47 +04:00
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-05-16 14:02:45 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-04-18 23:35:09 +03:00
|
|
|
nsFormFillController::MarkAsLoginManagerField(HTMLInputElement *aInput)
|
2007-05-16 14:02:45 +04:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* The Login Manager can supply autocomplete results for username fields,
|
|
|
|
* when a user has multiple logins stored for a site. It uses this
|
|
|
|
* interface to indicate that the form manager shouldn't handle the
|
|
|
|
* autocomplete. The form manager also checks for this tag when saving
|
|
|
|
* form history (so it doesn't save usernames).
|
|
|
|
*/
|
2018-04-18 23:35:09 +03:00
|
|
|
NS_ENSURE_STATE(aInput);
|
2017-01-12 05:03:42 +03:00
|
|
|
|
|
|
|
// If the field was already marked, we don't want to show the popup again.
|
2018-04-18 23:35:09 +03:00
|
|
|
if (mPwmgrInputs.Get(aInput)) {
|
2017-01-12 05:03:42 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-04-18 23:35:09 +03:00
|
|
|
mPwmgrInputs.Put(aInput, true);
|
|
|
|
aInput->AddMutationObserverUnlessExists(this);
|
2007-05-16 14:02:45 +04:00
|
|
|
|
2016-12-01 03:01:52 +03:00
|
|
|
nsFocusManager *fm = nsFocusManager::GetFocusManager();
|
|
|
|
if (fm) {
|
2018-04-26 22:28:31 +03:00
|
|
|
nsCOMPtr<nsIContent> focusedContent = fm->GetFocusedElement();
|
2018-04-18 23:35:09 +03:00
|
|
|
if (focusedContent == aInput) {
|
2016-12-01 03:01:52 +03:00
|
|
|
if (!mFocusedInput) {
|
2018-04-18 23:35:09 +03:00
|
|
|
MaybeStartControllingInput(aInput);
|
2016-12-01 03:01:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-17 01:56:28 +03:00
|
|
|
if (!mLoginManager) {
|
2007-10-12 00:23:52 +04:00
|
|
|
mLoginManager = do_GetService("@mozilla.org/login-manager;1");
|
2017-05-17 01:56:28 +03:00
|
|
|
}
|
2007-10-12 00:23:52 +04:00
|
|
|
|
2007-05-16 14:02:45 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-09-22 10:26:28 +03:00
|
|
|
NS_IMETHODIMP
|
2018-04-18 23:35:09 +03:00
|
|
|
nsFormFillController::MarkAsAutofillField(HTMLInputElement *aInput)
|
2016-09-22 10:26:28 +03:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Support other components implementing form autofill and handle autocomplete
|
|
|
|
* for the field.
|
|
|
|
*/
|
2018-04-18 23:35:09 +03:00
|
|
|
NS_ENSURE_STATE(aInput);
|
2017-02-23 09:44:07 +03:00
|
|
|
|
2017-07-22 01:32:18 +03:00
|
|
|
MOZ_LOG(sLogger, LogLevel::Verbose,
|
2018-04-18 23:35:09 +03:00
|
|
|
("MarkAsAutofillField: aInput = %p", aInput));
|
2017-07-22 01:32:18 +03:00
|
|
|
|
2018-04-18 23:35:09 +03:00
|
|
|
if (mAutofillInputs.Get(aInput)) {
|
2017-02-23 09:44:07 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-04-18 23:35:09 +03:00
|
|
|
mAutofillInputs.Put(aInput, true);
|
|
|
|
aInput->AddMutationObserverUnlessExists(this);
|
2016-09-22 10:26:28 +03:00
|
|
|
|
2018-04-18 23:35:09 +03:00
|
|
|
aInput->EnablePreview();
|
2017-03-22 11:55:56 +03:00
|
|
|
|
2017-02-23 09:44:07 +03:00
|
|
|
nsFocusManager *fm = nsFocusManager::GetFocusManager();
|
|
|
|
if (fm) {
|
2018-04-26 22:28:31 +03:00
|
|
|
nsCOMPtr<nsIContent> focusedContent = fm->GetFocusedElement();
|
2018-04-18 23:35:09 +03:00
|
|
|
if (focusedContent == aInput) {
|
|
|
|
MaybeStartControllingInput(aInput);
|
2017-02-23 09:44:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-22 10:26:28 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-12-30 12:00:27 +03:00
|
|
|
NS_IMETHODIMP
|
2018-04-18 23:35:09 +03:00
|
|
|
nsFormFillController::GetFocusedInput(HTMLInputElement **aInput)
|
2018-01-30 08:25:36 +03:00
|
|
|
{
|
2017-02-01 10:57:49 +03:00
|
|
|
*aInput = mFocusedInput;
|
|
|
|
NS_IF_ADDREF(*aInput);
|
2016-12-30 12:00:27 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-05-16 14:02:45 +04:00
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
//// nsIAutoCompleteInput
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFormFillController::GetPopup(nsIAutoCompletePopup **aPopup)
|
|
|
|
{
|
|
|
|
*aPopup = mFocusedPopup;
|
|
|
|
NS_IF_ADDREF(*aPopup);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-10-11 11:50:53 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFormFillController::GetController(nsIAutoCompleteController **aController)
|
|
|
|
{
|
|
|
|
*aController = mController;
|
|
|
|
NS_IF_ADDREF(*aController);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFormFillController::GetPopupOpen(bool *aPopupOpen)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
2017-05-17 01:56:28 +03:00
|
|
|
if (mFocusedPopup) {
|
2002-09-28 04:38:20 +04:00
|
|
|
mFocusedPopup->GetPopupOpen(aPopupOpen);
|
2017-05-17 01:56:28 +03:00
|
|
|
} else {
|
2011-10-17 18:59:28 +04:00
|
|
|
*aPopupOpen = false;
|
2017-05-17 01:56:28 +03:00
|
|
|
}
|
2002-09-28 04:38:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFormFillController::SetPopupOpen(bool aPopupOpen)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
2004-03-18 04:52:51 +03:00
|
|
|
if (mFocusedPopup) {
|
|
|
|
if (aPopupOpen) {
|
2006-07-18 04:32:24 +04:00
|
|
|
// make sure input field is visible before showing popup (bug 320938)
|
2018-01-30 08:25:36 +03:00
|
|
|
nsCOMPtr<nsIContent> content = mFocusedInput;
|
2006-09-09 01:19:58 +04:00
|
|
|
NS_ENSURE_STATE(content);
|
2006-07-18 04:32:24 +04:00
|
|
|
nsCOMPtr<nsIDocShell> docShell = GetDocShellForInput(mFocusedInput);
|
2006-08-29 20:11:08 +04:00
|
|
|
NS_ENSURE_STATE(docShell);
|
2012-12-29 05:56:42 +04:00
|
|
|
nsCOMPtr<nsIPresShell> presShell = docShell->GetPresShell();
|
2006-08-29 20:11:08 +04:00
|
|
|
NS_ENSURE_STATE(presShell);
|
2007-03-06 12:53:56 +03:00
|
|
|
presShell->ScrollContentIntoView(content,
|
2012-09-13 06:53:28 +04:00
|
|
|
nsIPresShell::ScrollAxis(
|
|
|
|
nsIPresShell::SCROLL_MINIMUM,
|
|
|
|
nsIPresShell::SCROLL_IF_NOT_VISIBLE),
|
|
|
|
nsIPresShell::ScrollAxis(
|
|
|
|
nsIPresShell::SCROLL_MINIMUM,
|
|
|
|
nsIPresShell::SCROLL_IF_NOT_VISIBLE),
|
2010-10-28 20:01:37 +04:00
|
|
|
nsIPresShell::SCROLL_OVERFLOW_HIDDEN);
|
2009-04-13 12:35:18 +04:00
|
|
|
// mFocusedPopup can be destroyed after ScrollContentIntoView, see bug 420089
|
2013-08-08 00:23:08 +04:00
|
|
|
if (mFocusedPopup) {
|
2018-01-30 08:25:36 +03:00
|
|
|
mFocusedPopup->OpenAutocompletePopup(this, mFocusedInput);
|
2013-08-08 00:23:08 +04:00
|
|
|
}
|
2017-05-17 01:56:28 +03:00
|
|
|
} else {
|
2004-03-18 04:52:51 +03:00
|
|
|
mFocusedPopup->ClosePopup();
|
2017-05-17 01:56:28 +03:00
|
|
|
}
|
2002-09-28 04:38:20 +04:00
|
|
|
}
|
2006-06-19 23:55:33 +04:00
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFormFillController::GetDisableAutoComplete(bool *aDisableAutoComplete)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
|
|
|
*aDisableAutoComplete = mDisableAutoComplete;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFormFillController::SetDisableAutoComplete(bool aDisableAutoComplete)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
|
|
|
mDisableAutoComplete = aDisableAutoComplete;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFormFillController::GetCompleteDefaultIndex(bool *aCompleteDefaultIndex)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
|
|
|
*aCompleteDefaultIndex = mCompleteDefaultIndex;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFormFillController::SetCompleteDefaultIndex(bool aCompleteDefaultIndex)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
|
|
|
mCompleteDefaultIndex = aCompleteDefaultIndex;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-02-18 15:40:00 +03:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFormFillController::GetCompleteSelectedIndex(bool *aCompleteSelectedIndex)
|
2005-02-18 15:40:00 +03:00
|
|
|
{
|
|
|
|
*aCompleteSelectedIndex = mCompleteSelectedIndex;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFormFillController::SetCompleteSelectedIndex(bool aCompleteSelectedIndex)
|
2005-02-18 15:40:00 +03:00
|
|
|
{
|
|
|
|
mCompleteSelectedIndex = aCompleteSelectedIndex;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFormFillController::GetForceComplete(bool *aForceComplete)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
|
|
|
*aForceComplete = mForceComplete;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP nsFormFillController::SetForceComplete(bool aForceComplete)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
|
|
|
mForceComplete = aForceComplete;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsFormFillController::GetMinResultsForPopup(uint32_t *aMinResultsForPopup)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
|
|
|
*aMinResultsForPopup = mMinResultsForPopup;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_IMETHODIMP nsFormFillController::SetMinResultsForPopup(uint32_t aMinResultsForPopup)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
|
|
|
mMinResultsForPopup = aMinResultsForPopup;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-07-13 06:27:25 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsFormFillController::GetMaxRows(uint32_t *aMaxRows)
|
2003-07-13 06:27:25 +04:00
|
|
|
{
|
|
|
|
*aMaxRows = mMaxRows;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsFormFillController::SetMaxRows(uint32_t aMaxRows)
|
2003-07-13 06:27:25 +04:00
|
|
|
{
|
|
|
|
mMaxRows = aMaxRows;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsFormFillController::GetTimeout(uint32_t *aTimeout)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
|
|
|
*aTimeout = mTimeout;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_IMETHODIMP nsFormFillController::SetTimeout(uint32_t aTimeout)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
|
|
|
mTimeout = aTimeout;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFormFillController::SetSearchParam(const nsAString &aSearchParam)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFormFillController::GetSearchParam(nsAString &aSearchParam)
|
|
|
|
{
|
2003-04-22 14:27:30 +04:00
|
|
|
if (!mFocusedInput) {
|
|
|
|
NS_WARNING("mFocusedInput is null for some reason! avoiding a crash. should find out why... - ben");
|
2011-08-04 04:52:47 +04:00
|
|
|
return NS_ERROR_FAILURE; // XXX why? fix me.
|
2003-04-22 14:27:30 +04:00
|
|
|
}
|
2011-08-04 04:52:47 +04:00
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
mFocusedInput->GetName(aSearchParam);
|
2013-08-08 00:23:08 +04:00
|
|
|
if (aSearchParam.IsEmpty()) {
|
2018-01-30 08:25:36 +03:00
|
|
|
mFocusedInput->GetId(aSearchParam);
|
2013-08-08 00:23:08 +04:00
|
|
|
}
|
2011-08-04 04:52:47 +04:00
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsFormFillController::GetSearchCount(uint32_t *aSearchCount)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
|
|
|
*aSearchCount = 1;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsFormFillController::GetSearchAt(uint32_t index, nsACString & _retval)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
2018-01-30 08:25:36 +03:00
|
|
|
if (mAutofillInputs.Get(mFocusedInput)) {
|
2017-07-22 01:32:18 +03:00
|
|
|
MOZ_LOG(sLogger, LogLevel::Debug, ("GetSearchAt: autofill-profiles field"));
|
2016-12-22 07:07:02 +03:00
|
|
|
nsCOMPtr<nsIAutoCompleteSearch> profileSearch = do_GetService("@mozilla.org/autocomplete/search;1?name=autofill-profiles");
|
|
|
|
if (profileSearch) {
|
|
|
|
_retval.AssignLiteral("autofill-profiles");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-22 01:32:18 +03:00
|
|
|
MOZ_LOG(sLogger, LogLevel::Debug, ("GetSearchAt: form-history field"));
|
2014-05-22 07:48:51 +04:00
|
|
|
_retval.AssignLiteral("form-history");
|
2002-09-28 04:38:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFormFillController::GetTextValue(nsAString & aTextValue)
|
|
|
|
{
|
2006-09-18 12:23:32 +04:00
|
|
|
if (mFocusedInput) {
|
2018-01-30 08:25:36 +03:00
|
|
|
mFocusedInput->GetValue(aTextValue, CallerType::System);
|
2006-09-18 12:23:32 +04:00
|
|
|
} else {
|
|
|
|
aTextValue.Truncate();
|
|
|
|
}
|
2002-09-28 04:38:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFormFillController::SetTextValue(const nsAString & aTextValue)
|
|
|
|
{
|
2018-01-30 08:25:36 +03:00
|
|
|
if (mFocusedInput) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mSuppressOnInput = true;
|
2018-06-02 05:35:23 +03:00
|
|
|
mFocusedInput->SetUserInput(aTextValue,
|
|
|
|
*nsContentUtils::GetSystemPrincipal());
|
2011-10-17 18:59:28 +04:00
|
|
|
mSuppressOnInput = false;
|
2006-09-18 12:23:32 +04:00
|
|
|
}
|
2018-01-30 08:25:36 +03:00
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-09-21 22:55:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFormFillController::SetTextValueWithReason(const nsAString & aTextValue,
|
|
|
|
uint16_t aReason)
|
|
|
|
{
|
|
|
|
return SetTextValue(aTextValue);
|
|
|
|
}
|
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsFormFillController::GetSelectionStart(int32_t *aSelectionStart)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
2018-01-30 08:25:36 +03:00
|
|
|
if (!mFocusedInput) {
|
2017-03-09 22:44:03 +03:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
ErrorResult rv;
|
2018-01-30 08:25:36 +03:00
|
|
|
*aSelectionStart = mFocusedInput->GetSelectionStartIgnoringType(rv);
|
2017-03-09 22:44:03 +03:00
|
|
|
return rv.StealNSResult();
|
2002-09-28 04:38:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsFormFillController::GetSelectionEnd(int32_t *aSelectionEnd)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
2018-01-30 08:25:36 +03:00
|
|
|
if (!mFocusedInput) {
|
2017-03-09 22:44:03 +03:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
ErrorResult rv;
|
2018-01-30 08:25:36 +03:00
|
|
|
*aSelectionEnd = mFocusedInput->GetSelectionEndIgnoringType(rv);
|
2017-03-09 22:44:03 +03:00
|
|
|
return rv.StealNSResult();
|
2002-09-28 04:38:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsFormFillController::SelectTextRange(int32_t aStartIndex, int32_t aEndIndex)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
2018-01-30 08:25:36 +03:00
|
|
|
if (!mFocusedInput) {
|
2017-03-09 22:44:06 +03:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
ErrorResult rv;
|
2018-01-30 08:25:36 +03:00
|
|
|
mFocusedInput->SetSelectionRange(aStartIndex, aEndIndex,
|
|
|
|
Optional<nsAString>(), rv);
|
2017-03-09 22:44:06 +03:00
|
|
|
return rv.StealNSResult();
|
2002-09-28 04:38:20 +04:00
|
|
|
}
|
|
|
|
|
2008-02-22 02:17:33 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFormFillController::OnSearchBegin()
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFormFillController::OnSearchComplete()
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-04-20 19:53:17 +03:00
|
|
|
nsFormFillController::OnTextEntered(Event* aEvent,
|
2016-08-03 04:00:26 +03:00
|
|
|
bool* aPrevent)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
2006-10-09 21:58:11 +04:00
|
|
|
NS_ENSURE_ARG(aPrevent);
|
2018-01-30 08:25:36 +03:00
|
|
|
NS_ENSURE_TRUE(mFocusedInput, NS_OK);
|
2003-08-04 04:57:26 +04:00
|
|
|
// Fire off a DOMAutoComplete event
|
|
|
|
|
2018-01-31 23:18:11 +03:00
|
|
|
IgnoredErrorResult ignored;
|
|
|
|
RefPtr<Event> event = mFocusedInput->OwnerDoc()->
|
|
|
|
CreateEvent(NS_LITERAL_STRING("Events"), CallerType::System, ignored);
|
2012-06-11 03:44:50 +04:00
|
|
|
NS_ENSURE_STATE(event);
|
2003-08-04 04:57:26 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
event->InitEvent(NS_LITERAL_STRING("DOMAutoComplete"), true, true);
|
2005-04-29 03:48:28 +04:00
|
|
|
|
2006-10-09 21:58:11 +04:00
|
|
|
// XXXjst: We mark this event as a trusted event, it's up to the
|
|
|
|
// callers of this to ensure that it's only called from trusted
|
|
|
|
// code.
|
2012-06-11 03:44:50 +04:00
|
|
|
event->SetTrusted(true);
|
2005-04-29 03:48:28 +04:00
|
|
|
|
2018-04-05 20:42:41 +03:00
|
|
|
bool defaultActionEnabled =
|
|
|
|
mFocusedInput->DispatchEvent(*event, CallerType::System, IgnoreErrors());
|
2006-10-09 21:58:11 +04:00
|
|
|
*aPrevent = !defaultActionEnabled;
|
2002-09-28 04:38:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFormFillController::OnTextReverted(bool *_retval)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-05-31 21:55:19 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFormFillController::GetConsumeRollupEvent(bool *aConsumeRollupEvent)
|
2006-05-31 21:55:19 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
*aConsumeRollupEvent = false;
|
2006-05-31 21:55:19 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-02-18 10:40:10 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFormFillController::GetInPrivateContext(bool *aInPrivateContext)
|
|
|
|
{
|
2018-01-30 08:25:36 +03:00
|
|
|
if (!mFocusedInput) {
|
2012-02-18 10:40:10 +04:00
|
|
|
*aInPrivateContext = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-01-30 08:25:36 +03:00
|
|
|
nsCOMPtr<nsIDocument> doc = mFocusedInput->OwnerDoc();
|
2013-11-15 20:32:12 +04:00
|
|
|
nsCOMPtr<nsILoadContext> loadContext = doc->GetLoadContext();
|
2012-02-18 10:40:10 +04:00
|
|
|
*aInPrivateContext = loadContext && loadContext->UsePrivateBrowsing();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-02-02 23:53:55 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFormFillController::GetNoRollupOnCaretMove(bool *aNoRollupOnCaretMove)
|
|
|
|
{
|
|
|
|
*aNoRollupOnCaretMove = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-05-16 14:02:45 +04:00
|
|
|
|
2016-05-31 13:59:41 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFormFillController::GetUserContextId(uint32_t* aUserContextId)
|
|
|
|
{
|
|
|
|
*aUserContextId = nsIScriptSecurityManager::DEFAULT_USER_CONTEXT_ID;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
//// nsIAutoCompleteSearch
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFormFillController::StartSearch(const nsAString &aSearchString, const nsAString &aSearchParam,
|
|
|
|
nsIAutoCompleteResult *aPreviousResult, nsIAutoCompleteObserver *aListener)
|
|
|
|
{
|
2017-07-22 01:32:18 +03:00
|
|
|
MOZ_LOG(sLogger, LogLevel::Debug, ("StartSearch for %p", mFocusedInput));
|
|
|
|
|
2009-06-20 00:19:18 +04:00
|
|
|
nsresult rv;
|
2006-01-26 22:17:04 +03:00
|
|
|
|
2007-05-16 14:02:45 +04:00
|
|
|
// If the login manager has indicated it's responsible for this field, let it
|
|
|
|
// handle the autocomplete. Otherwise, handle with form history.
|
2017-02-07 06:15:35 +03:00
|
|
|
// This method is sometimes called in unit tests and from XUL without a focused node.
|
2018-01-30 08:25:36 +03:00
|
|
|
if (mFocusedInput &&
|
|
|
|
(mPwmgrInputs.Get(mFocusedInput) ||
|
|
|
|
mFocusedInput->ControlType() == NS_FORM_INPUT_PASSWORD)) {
|
2017-07-22 01:32:18 +03:00
|
|
|
MOZ_LOG(sLogger, LogLevel::Debug, ("StartSearch: login field"));
|
2017-01-31 02:53:27 +03:00
|
|
|
|
|
|
|
// Handle the case where a password field is focused but
|
|
|
|
// MarkAsLoginManagerField wasn't called because password manager is disabled.
|
|
|
|
if (!mLoginManager) {
|
|
|
|
mLoginManager = do_GetService("@mozilla.org/login-manager;1");
|
|
|
|
}
|
|
|
|
|
2017-02-07 06:15:35 +03:00
|
|
|
if (NS_WARN_IF(!mLoginManager)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2007-05-16 14:02:45 +04:00
|
|
|
// XXX aPreviousResult shouldn't ever be a historyResult type, since we're not letting
|
|
|
|
// satchel manage the field?
|
2014-06-28 22:09:45 +04:00
|
|
|
mLastListener = aListener;
|
|
|
|
rv = mLoginManager->AutoCompleteSearchAsync(aSearchString,
|
|
|
|
aPreviousResult,
|
|
|
|
mFocusedInput,
|
|
|
|
this);
|
2013-04-20 02:21:30 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-05-16 14:02:45 +04:00
|
|
|
} else {
|
2017-07-22 01:32:18 +03:00
|
|
|
MOZ_LOG(sLogger, LogLevel::Debug, ("StartSearch: non-login field"));
|
2013-04-20 02:21:30 +04:00
|
|
|
mLastListener = aListener;
|
2011-11-20 22:02:47 +04:00
|
|
|
|
2015-05-28 19:55:46 +03:00
|
|
|
nsCOMPtr<nsIAutoCompleteResult> datalistResult;
|
|
|
|
if (mFocusedInput) {
|
|
|
|
rv = PerformInputListAutoComplete(aSearchString,
|
|
|
|
getter_AddRefs(datalistResult));
|
2010-09-10 09:19:20 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2015-05-28 19:55:46 +03:00
|
|
|
|
2017-06-14 07:49:45 +03:00
|
|
|
auto formAutoComplete = GetFormAutoComplete();
|
|
|
|
NS_ENSURE_TRUE(formAutoComplete, NS_ERROR_FAILURE);
|
2015-05-28 19:55:46 +03:00
|
|
|
|
|
|
|
formAutoComplete->AutoCompleteSearchAsync(aSearchParam,
|
|
|
|
aSearchString,
|
|
|
|
mFocusedInput,
|
|
|
|
aPreviousResult,
|
|
|
|
datalistResult,
|
|
|
|
this);
|
|
|
|
mLastFormAutoComplete = formAutoComplete;
|
2013-04-20 02:21:30 +04:00
|
|
|
}
|
2010-09-10 09:19:20 +04:00
|
|
|
|
2013-04-20 02:21:30 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-09-10 09:20:16 +04:00
|
|
|
|
2013-04-20 02:21:30 +04:00
|
|
|
nsresult
|
2015-05-28 19:55:46 +03:00
|
|
|
nsFormFillController::PerformInputListAutoComplete(const nsAString& aSearch,
|
|
|
|
nsIAutoCompleteResult** aResult)
|
2013-04-20 02:21:30 +04:00
|
|
|
{
|
|
|
|
// If an <input> is focused, check if it has a list="<datalist>" which can
|
|
|
|
// provide the list of suggestions.
|
2009-06-20 00:19:18 +04:00
|
|
|
|
2018-01-30 08:25:36 +03:00
|
|
|
MOZ_ASSERT(!mPwmgrInputs.Get(mFocusedInput));
|
2013-04-20 02:21:30 +04:00
|
|
|
nsresult rv;
|
2010-09-10 09:20:16 +04:00
|
|
|
|
2015-05-28 19:55:46 +03:00
|
|
|
nsCOMPtr <nsIInputListAutoComplete> inputListAutoComplete =
|
|
|
|
do_GetService("@mozilla.org/satchel/inputlist-autocomplete;1", &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = inputListAutoComplete->AutoCompleteSearch(aSearch,
|
|
|
|
mFocusedInput,
|
|
|
|
aResult);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-04-20 02:21:30 +04:00
|
|
|
|
2015-05-28 19:55:46 +03:00
|
|
|
if (mFocusedInput) {
|
2018-01-30 08:25:36 +03:00
|
|
|
Element* list = mFocusedInput->GetList();
|
2015-05-28 19:55:46 +03:00
|
|
|
|
|
|
|
// Add a mutation observer to check for changes to the items in the <datalist>
|
|
|
|
// and update the suggestions accordingly.
|
2018-01-30 08:25:36 +03:00
|
|
|
if (mListNode != list) {
|
2015-05-28 19:55:46 +03:00
|
|
|
if (mListNode) {
|
|
|
|
mListNode->RemoveMutationObserver(this);
|
|
|
|
mListNode = nullptr;
|
|
|
|
}
|
2018-01-30 08:25:36 +03:00
|
|
|
if (list) {
|
|
|
|
list->AddMutationObserverUnlessExists(this);
|
|
|
|
mListNode = list;
|
2010-09-10 09:20:16 +04:00
|
|
|
}
|
|
|
|
}
|
2013-04-20 02:21:30 +04:00
|
|
|
}
|
2011-08-04 04:52:47 +04:00
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-10 09:20:16 +04:00
|
|
|
void nsFormFillController::RevalidateDataList()
|
|
|
|
{
|
2012-02-22 16:59:39 +04:00
|
|
|
if (!mLastListener) {
|
|
|
|
return;
|
|
|
|
}
|
2015-05-28 19:55:46 +03:00
|
|
|
|
2017-04-06 23:39:08 +03:00
|
|
|
nsCOMPtr<nsIAutoCompleteController> controller(do_QueryInterface(mLastListener));
|
|
|
|
if (!controller) {
|
2015-05-28 19:55:46 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-06 23:39:08 +03:00
|
|
|
controller->StartSearch(mLastSearchString);
|
2010-09-10 09:20:16 +04:00
|
|
|
}
|
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFormFillController::StopSearch()
|
|
|
|
{
|
2013-04-20 02:21:30 +04:00
|
|
|
// Make sure to stop and clear this, otherwise the controller will prevent
|
|
|
|
// mLastFormAutoComplete from being deleted.
|
|
|
|
if (mLastFormAutoComplete) {
|
|
|
|
mLastFormAutoComplete->StopAutoCompleteSearch();
|
|
|
|
mLastFormAutoComplete = nullptr;
|
2016-04-12 22:19:58 +03:00
|
|
|
} else if (mLoginManager) {
|
|
|
|
mLoginManager->StopSearch();
|
2013-04-20 02:21:30 +04:00
|
|
|
}
|
2002-09-28 04:38:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-12-14 05:11:45 +03:00
|
|
|
nsresult
|
2018-01-30 08:25:36 +03:00
|
|
|
nsFormFillController::StartQueryLoginReputation(HTMLInputElement *aInput)
|
2017-12-14 05:11:45 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-04-20 02:21:30 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
//// nsIFormAutoCompleteObserver
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFormFillController::OnSearchCompletion(nsIAutoCompleteResult *aResult)
|
|
|
|
{
|
|
|
|
nsAutoString searchString;
|
2015-05-28 19:55:46 +03:00
|
|
|
aResult->GetSearchString(searchString);
|
|
|
|
|
2013-04-20 02:21:30 +04:00
|
|
|
mLastSearchString = searchString;
|
|
|
|
|
2015-05-28 19:55:46 +03:00
|
|
|
if (mLastListener) {
|
|
|
|
mLastListener->OnSearchResult(this, aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2013-04-20 02:21:30 +04:00
|
|
|
}
|
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
//// nsIDOMEventListener
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-04-20 07:49:29 +03:00
|
|
|
nsFormFillController::HandleEvent(Event* aEvent)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
2017-06-15 00:54:35 +03:00
|
|
|
WidgetEvent* internalEvent = aEvent->WidgetEventPtr();
|
|
|
|
NS_ENSURE_STATE(internalEvent);
|
2007-05-16 14:02:45 +04:00
|
|
|
|
2017-06-15 00:54:35 +03:00
|
|
|
switch (internalEvent->mMessage) {
|
|
|
|
case eFocus:
|
2011-06-28 03:34:56 +04:00
|
|
|
return Focus(aEvent);
|
2017-06-15 00:54:35 +03:00
|
|
|
case eMouseDown:
|
2011-06-28 03:34:56 +04:00
|
|
|
return MouseDown(aEvent);
|
2018-06-22 13:37:09 +03:00
|
|
|
case eKeyDown:
|
|
|
|
return KeyDown(aEvent);
|
2017-06-15 00:54:35 +03:00
|
|
|
case eKeyPress:
|
2011-06-28 03:34:56 +04:00
|
|
|
return KeyPress(aEvent);
|
2017-06-15 00:54:35 +03:00
|
|
|
case eEditorInput:
|
|
|
|
{
|
2018-04-20 07:49:30 +03:00
|
|
|
nsCOMPtr<nsINode> input = do_QueryInterface(aEvent->GetTarget());
|
2017-06-21 04:37:20 +03:00
|
|
|
if (!IsTextControl(input)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-06-15 00:54:35 +03:00
|
|
|
bool unused = false;
|
|
|
|
return (!mSuppressOnInput && mController && mFocusedInput) ?
|
|
|
|
mController->HandleText(&unused) : NS_OK;
|
|
|
|
}
|
|
|
|
case eBlur:
|
2017-05-17 01:56:28 +03:00
|
|
|
if (mFocusedInput) {
|
2011-06-28 03:34:56 +04:00
|
|
|
StopControllingInput();
|
2017-05-17 01:56:28 +03:00
|
|
|
}
|
2011-06-28 03:34:56 +04:00
|
|
|
return NS_OK;
|
2017-06-15 00:54:35 +03:00
|
|
|
case eCompositionStart:
|
2011-06-28 03:34:56 +04:00
|
|
|
NS_ASSERTION(mController, "should have a controller!");
|
2017-05-17 01:56:28 +03:00
|
|
|
if (mController && mFocusedInput) {
|
2011-06-28 03:34:56 +04:00
|
|
|
mController->HandleStartComposition();
|
2017-05-17 01:56:28 +03:00
|
|
|
}
|
2011-06-28 03:34:56 +04:00
|
|
|
return NS_OK;
|
2017-06-15 00:54:35 +03:00
|
|
|
case eCompositionEnd:
|
2011-06-28 03:34:56 +04:00
|
|
|
NS_ASSERTION(mController, "should have a controller!");
|
2017-05-17 01:56:28 +03:00
|
|
|
if (mController && mFocusedInput) {
|
2011-06-28 03:34:56 +04:00
|
|
|
mController->HandleEndComposition();
|
2017-05-17 01:56:28 +03:00
|
|
|
}
|
2011-06-28 03:34:56 +04:00
|
|
|
return NS_OK;
|
2017-06-15 00:54:35 +03:00
|
|
|
case eContextMenu:
|
2017-05-17 01:56:28 +03:00
|
|
|
if (mFocusedPopup) {
|
2011-06-28 03:34:56 +04:00
|
|
|
mFocusedPopup->ClosePopup();
|
2017-05-17 01:56:28 +03:00
|
|
|
}
|
2011-06-28 03:34:56 +04:00
|
|
|
return NS_OK;
|
2017-06-15 00:54:35 +03:00
|
|
|
case ePageHide:
|
|
|
|
{
|
2018-04-20 07:49:30 +03:00
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(aEvent->GetTarget());
|
2017-06-15 00:54:35 +03:00
|
|
|
if (!doc) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-05-16 14:02:45 +04:00
|
|
|
|
2017-06-15 00:54:35 +03:00
|
|
|
if (mFocusedInput) {
|
2018-01-30 08:25:36 +03:00
|
|
|
if (doc == mFocusedInput->OwnerDoc()) {
|
2017-06-15 00:54:35 +03:00
|
|
|
StopControllingInput();
|
|
|
|
}
|
2017-05-17 01:56:28 +03:00
|
|
|
}
|
2008-02-27 08:06:13 +03:00
|
|
|
|
2017-07-21 23:32:48 +03:00
|
|
|
// Only remove the observer notifications and marked autofill and password
|
|
|
|
// manager fields if the page isn't going to be persisted (i.e. it's being
|
|
|
|
// unloaded) so that appropriate autocomplete handling works with bfcache.
|
2018-04-20 07:49:30 +03:00
|
|
|
bool persisted = aEvent->AsPageTransitionEvent()->Persisted();
|
2017-07-21 23:32:48 +03:00
|
|
|
if (!persisted) {
|
|
|
|
RemoveForDocument(doc);
|
|
|
|
}
|
2017-06-15 00:54:35 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// Handling the default case to shut up stupid -Wswitch warnings.
|
|
|
|
// One day compilers will be smarter...
|
|
|
|
break;
|
2007-05-16 14:02:45 +04:00
|
|
|
}
|
|
|
|
|
2011-08-04 04:52:47 +04:00
|
|
|
return NS_OK;
|
2002-09-28 04:38:20 +04:00
|
|
|
}
|
|
|
|
|
2015-11-25 03:53:46 +03:00
|
|
|
void
|
|
|
|
nsFormFillController::RemoveForDocument(nsIDocument* aDoc)
|
|
|
|
{
|
2017-07-21 23:32:48 +03:00
|
|
|
MOZ_LOG(sLogger, LogLevel::Verbose, ("RemoveForDocument: %p", aDoc));
|
2015-11-25 03:53:46 +03:00
|
|
|
for (auto iter = mPwmgrInputs.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
const nsINode* key = iter.Key();
|
|
|
|
if (key && (!aDoc || key->OwnerDoc() == aDoc)) {
|
2018-01-30 08:25:36 +03:00
|
|
|
// mFocusedInput's observer is tracked separately, so don't remove it
|
2015-11-25 03:53:46 +03:00
|
|
|
// here.
|
2018-01-30 08:25:36 +03:00
|
|
|
if (key != mFocusedInput) {
|
2016-09-22 10:26:28 +03:00
|
|
|
const_cast<nsINode*>(key)->RemoveMutationObserver(this);
|
|
|
|
}
|
|
|
|
iter.Remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto iter = mAutofillInputs.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
const nsINode* key = iter.Key();
|
|
|
|
if (key && (!aDoc || key->OwnerDoc() == aDoc)) {
|
2018-01-30 08:25:36 +03:00
|
|
|
// mFocusedInput's observer is tracked separately, so don't remove it
|
2016-09-22 10:26:28 +03:00
|
|
|
// here.
|
2018-01-30 08:25:36 +03:00
|
|
|
if (key != mFocusedInput) {
|
2015-11-25 03:53:46 +03:00
|
|
|
const_cast<nsINode*>(key)->RemoveMutationObserver(this);
|
|
|
|
}
|
|
|
|
iter.Remove();
|
2012-02-28 03:31:23 +04:00
|
|
|
}
|
2012-02-22 16:59:39 +04:00
|
|
|
}
|
2007-05-16 14:02:45 +04:00
|
|
|
}
|
|
|
|
|
2017-06-21 04:37:20 +03:00
|
|
|
bool
|
|
|
|
nsFormFillController::IsTextControl(nsINode* aNode)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(aNode);
|
|
|
|
return formControl &&
|
|
|
|
formControl->IsSingleLineTextControl(false);
|
|
|
|
}
|
|
|
|
|
2015-01-24 20:37:47 +03:00
|
|
|
void
|
2018-01-30 08:25:36 +03:00
|
|
|
nsFormFillController::MaybeStartControllingInput(HTMLInputElement* aInput)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
2017-07-22 01:32:18 +03:00
|
|
|
MOZ_LOG(sLogger, LogLevel::Verbose, ("MaybeStartControllingInput for %p", aInput));
|
2018-01-30 08:25:36 +03:00
|
|
|
if (!aInput) {
|
2015-01-24 20:37:47 +03:00
|
|
|
return;
|
2017-05-17 01:56:28 +03:00
|
|
|
}
|
2003-04-22 14:27:30 +04:00
|
|
|
|
2018-01-30 08:25:36 +03:00
|
|
|
if (!IsTextControl(aInput)) {
|
2015-01-24 20:37:47 +03:00
|
|
|
return;
|
2017-05-17 01:56:28 +03:00
|
|
|
}
|
2013-07-25 03:57:46 +04:00
|
|
|
|
2018-01-30 08:25:36 +03:00
|
|
|
if (aInput->ReadOnly()) {
|
2015-01-24 20:37:47 +03:00
|
|
|
return;
|
2017-05-17 01:56:28 +03:00
|
|
|
}
|
2010-09-10 09:19:20 +04:00
|
|
|
|
2015-01-24 20:37:47 +03:00
|
|
|
bool autocomplete = nsContentUtils::IsAutocompleteEnabled(aInput);
|
2011-11-20 22:02:47 +04:00
|
|
|
|
2018-01-30 08:25:36 +03:00
|
|
|
bool hasList = aInput->GetList() != nullptr;
|
2010-09-10 09:19:20 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isPwmgrInput = false;
|
2018-01-30 08:25:36 +03:00
|
|
|
if (mPwmgrInputs.Get(aInput) ||
|
|
|
|
aInput->ControlType() == NS_FORM_INPUT_PASSWORD) {
|
2017-02-07 06:15:35 +03:00
|
|
|
isPwmgrInput = true;
|
|
|
|
}
|
2010-09-10 09:19:20 +04:00
|
|
|
|
2017-09-11 07:11:12 +03:00
|
|
|
bool isAutofillInput = false;
|
2018-01-30 08:25:36 +03:00
|
|
|
if (mAutofillInputs.Get(aInput)) {
|
2017-09-11 07:11:12 +03:00
|
|
|
isAutofillInput = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isAutofillInput || isPwmgrInput || hasList || autocomplete) {
|
2015-01-24 20:37:47 +03:00
|
|
|
StartControllingInput(aInput);
|
2010-09-10 09:19:20 +04:00
|
|
|
}
|
2017-12-14 05:11:45 +03:00
|
|
|
|
|
|
|
#ifdef NIGHTLY_BUILD
|
|
|
|
// Trigger an asynchronous login reputation query when user focuses on the
|
|
|
|
// password field.
|
2018-01-30 08:25:36 +03:00
|
|
|
if (aInput->ControlType() == NS_FORM_INPUT_PASSWORD) {
|
2017-12-14 05:11:45 +03:00
|
|
|
StartQueryLoginReputation(aInput);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-01-24 20:37:47 +03:00
|
|
|
}
|
2011-08-04 04:52:47 +04:00
|
|
|
|
2015-01-24 20:37:47 +03:00
|
|
|
nsresult
|
2018-04-20 07:49:30 +03:00
|
|
|
nsFormFillController::Focus(Event* aEvent)
|
2015-01-24 20:37:47 +03:00
|
|
|
{
|
2018-04-20 07:49:30 +03:00
|
|
|
nsCOMPtr<nsIContent> input = do_QueryInterface(aEvent->GetTarget());
|
2018-03-22 00:39:04 +03:00
|
|
|
MaybeStartControllingInput(HTMLInputElement::FromNodeOrNull(input));
|
2016-11-21 18:20:44 +03:00
|
|
|
|
2017-01-31 02:53:27 +03:00
|
|
|
// Bail if we didn't start controlling the input.
|
2018-01-30 08:25:36 +03:00
|
|
|
if (!mFocusedInput) {
|
2017-01-31 02:53:27 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-02-07 06:15:35 +03:00
|
|
|
#ifndef ANDROID
|
2017-04-07 01:01:31 +03:00
|
|
|
// If this focus doesn't follow a right click within our specified
|
|
|
|
// threshold then show the autocomplete popup for all password fields.
|
|
|
|
// This is done to avoid showing both the context menu and the popup
|
|
|
|
// at the same time.
|
|
|
|
// We use a timestamp instead of a bool to avoid complexity when dealing with
|
|
|
|
// multiple input forms and the fact that a mousedown into an already focused
|
|
|
|
// field does not trigger another focus.
|
|
|
|
|
2018-01-30 08:25:36 +03:00
|
|
|
if (mFocusedInput->ControlType() != NS_FORM_INPUT_PASSWORD) {
|
2017-04-07 01:01:31 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have not seen a right click yet, just show the popup.
|
|
|
|
if (mLastRightClickTimeStamp.IsNull()) {
|
|
|
|
ShowPopup();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t timeDiff = (TimeStamp::Now() - mLastRightClickTimeStamp).ToMilliseconds();
|
|
|
|
if (timeDiff > mFocusAfterRightClickThreshold) {
|
|
|
|
ShowPopup();
|
|
|
|
}
|
2017-02-07 06:15:35 +03:00
|
|
|
#endif
|
2016-11-21 18:20:44 +03:00
|
|
|
|
2010-09-10 09:19:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2008-05-09 07:34:46 +04:00
|
|
|
|
2018-06-22 13:37:09 +03:00
|
|
|
nsresult
|
|
|
|
nsFormFillController::KeyDown(Event* aEvent)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mController, "should have a controller!");
|
|
|
|
if (!mFocusedInput || !mController) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<KeyboardEvent> keyEvent = aEvent->AsKeyboardEvent();
|
|
|
|
if (!keyEvent) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cancel = false;
|
|
|
|
uint32_t k = keyEvent->KeyCode();
|
|
|
|
switch (k) {
|
|
|
|
case KeyboardEvent_Binding::DOM_VK_RETURN: {
|
|
|
|
mController->HandleEnter(false, aEvent, &cancel);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cancel) {
|
|
|
|
aEvent->PreventDefault();
|
|
|
|
// Don't let the page see the RETURN event when the popup is open
|
|
|
|
// (indicated by cancel=true) so sites don't manually submit forms
|
|
|
|
// (e.g. via submit.click()) without the autocompleted value being filled.
|
|
|
|
// Bug 286933 will fix this for other key events.
|
|
|
|
if (k == KeyboardEvent_Binding::DOM_VK_RETURN) {
|
|
|
|
aEvent->StopPropagation();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-06-28 03:34:56 +04:00
|
|
|
nsresult
|
2018-04-20 07:49:30 +03:00
|
|
|
nsFormFillController::KeyPress(Event* aEvent)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
2004-07-29 12:42:54 +04:00
|
|
|
NS_ASSERTION(mController, "should have a controller!");
|
2017-05-17 01:56:28 +03:00
|
|
|
if (!mFocusedInput || !mController) {
|
2004-07-29 12:42:54 +04:00
|
|
|
return NS_OK;
|
2017-05-17 01:56:28 +03:00
|
|
|
}
|
2004-07-29 12:42:54 +04:00
|
|
|
|
2018-04-20 07:49:30 +03:00
|
|
|
RefPtr<KeyboardEvent> keyEvent = aEvent->AsKeyboardEvent();
|
2017-05-17 01:56:28 +03:00
|
|
|
if (!keyEvent) {
|
2004-07-29 12:42:54 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2017-05-17 01:56:28 +03:00
|
|
|
}
|
2003-10-22 12:45:54 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool cancel = false;
|
2016-09-07 18:44:46 +03:00
|
|
|
bool unused = false;
|
2002-09-28 04:38:20 +04:00
|
|
|
|
2018-02-09 19:17:09 +03:00
|
|
|
uint32_t k = keyEvent->KeyCode();
|
2003-07-13 06:31:08 +04:00
|
|
|
switch (k) {
|
2018-06-26 00:20:54 +03:00
|
|
|
case KeyboardEvent_Binding::DOM_VK_DELETE:
|
2006-04-06 02:57:48 +04:00
|
|
|
#ifndef XP_MACOSX
|
2006-02-01 00:16:11 +03:00
|
|
|
mController->HandleDelete(&cancel);
|
|
|
|
break;
|
2018-06-26 00:20:54 +03:00
|
|
|
case KeyboardEvent_Binding::DOM_VK_BACK_SPACE:
|
2016-09-07 18:44:46 +03:00
|
|
|
mController->HandleText(&unused);
|
2006-06-26 10:37:00 +04:00
|
|
|
break;
|
2006-04-06 02:57:48 +04:00
|
|
|
#else
|
2018-06-26 00:20:54 +03:00
|
|
|
case KeyboardEvent_Binding::DOM_VK_BACK_SPACE:
|
2006-04-06 02:57:48 +04:00
|
|
|
{
|
2018-02-09 19:17:09 +03:00
|
|
|
if (keyEvent->ShiftKey()) {
|
2006-04-06 02:57:48 +04:00
|
|
|
mController->HandleDelete(&cancel);
|
2016-09-07 18:44:46 +03:00
|
|
|
} else {
|
|
|
|
mController->HandleText(&unused);
|
|
|
|
}
|
2006-06-26 10:37:00 +04:00
|
|
|
|
|
|
|
break;
|
2006-04-06 02:57:48 +04:00
|
|
|
}
|
|
|
|
#endif
|
2018-06-26 00:20:54 +03:00
|
|
|
case KeyboardEvent_Binding::DOM_VK_PAGE_UP:
|
|
|
|
case KeyboardEvent_Binding::DOM_VK_PAGE_DOWN:
|
2007-12-18 12:16:42 +03:00
|
|
|
{
|
2018-02-09 19:17:09 +03:00
|
|
|
if (keyEvent->CtrlKey() ||
|
|
|
|
keyEvent->AltKey() ||
|
|
|
|
keyEvent->MetaKey()) {
|
2007-12-18 12:16:42 +03:00
|
|
|
break;
|
2017-05-17 01:56:28 +03:00
|
|
|
}
|
2007-12-18 12:16:42 +03:00
|
|
|
}
|
2016-01-02 03:02:54 +03:00
|
|
|
MOZ_FALLTHROUGH;
|
2018-06-26 00:20:54 +03:00
|
|
|
case KeyboardEvent_Binding::DOM_VK_UP:
|
|
|
|
case KeyboardEvent_Binding::DOM_VK_DOWN:
|
|
|
|
case KeyboardEvent_Binding::DOM_VK_LEFT:
|
|
|
|
case KeyboardEvent_Binding::DOM_VK_RIGHT:
|
2014-11-22 17:39:05 +03:00
|
|
|
{
|
|
|
|
// Get the writing-mode of the relevant input element,
|
|
|
|
// so that we can remap arrow keys if necessary.
|
|
|
|
mozilla::WritingMode wm;
|
2018-01-30 08:25:36 +03:00
|
|
|
if (mFocusedInput) {
|
|
|
|
nsIFrame *frame = mFocusedInput->GetPrimaryFrame();
|
2014-11-22 17:39:05 +03:00
|
|
|
if (frame) {
|
|
|
|
wm = frame->GetWritingMode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (wm.IsVertical()) {
|
|
|
|
switch (k) {
|
2018-06-26 00:20:54 +03:00
|
|
|
case KeyboardEvent_Binding::DOM_VK_LEFT:
|
|
|
|
k = wm.IsVerticalLR() ? KeyboardEvent_Binding::DOM_VK_UP
|
|
|
|
: KeyboardEvent_Binding::DOM_VK_DOWN;
|
2014-11-22 17:39:05 +03:00
|
|
|
break;
|
2018-06-26 00:20:54 +03:00
|
|
|
case KeyboardEvent_Binding::DOM_VK_RIGHT:
|
|
|
|
k = wm.IsVerticalLR() ? KeyboardEvent_Binding::DOM_VK_DOWN
|
|
|
|
: KeyboardEvent_Binding::DOM_VK_UP;
|
2014-11-22 17:39:05 +03:00
|
|
|
break;
|
2018-06-26 00:20:54 +03:00
|
|
|
case KeyboardEvent_Binding::DOM_VK_UP:
|
|
|
|
k = KeyboardEvent_Binding::DOM_VK_LEFT;
|
2014-11-22 17:39:05 +03:00
|
|
|
break;
|
2018-06-26 00:20:54 +03:00
|
|
|
case KeyboardEvent_Binding::DOM_VK_DOWN:
|
|
|
|
k = KeyboardEvent_Binding::DOM_VK_RIGHT;
|
2014-11-22 17:39:05 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-12-07 15:59:02 +03:00
|
|
|
mController->HandleKeyNavigation(k, &cancel);
|
2003-07-13 06:31:08 +04:00
|
|
|
break;
|
2018-06-26 00:20:54 +03:00
|
|
|
case KeyboardEvent_Binding::DOM_VK_ESCAPE:
|
2003-07-13 06:31:08 +04:00
|
|
|
mController->HandleEscape(&cancel);
|
|
|
|
break;
|
2018-06-26 00:20:54 +03:00
|
|
|
case KeyboardEvent_Binding::DOM_VK_TAB:
|
2003-07-13 06:31:08 +04:00
|
|
|
mController->HandleTab();
|
2011-10-17 18:59:28 +04:00
|
|
|
cancel = false;
|
2003-07-13 06:31:08 +04:00
|
|
|
break;
|
2002-09-28 04:38:20 +04:00
|
|
|
}
|
2011-08-04 04:52:47 +04:00
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
if (cancel) {
|
|
|
|
aEvent->PreventDefault();
|
|
|
|
}
|
2011-08-04 04:52:47 +04:00
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-06-28 03:34:56 +04:00
|
|
|
nsresult
|
2018-04-20 07:49:30 +03:00
|
|
|
nsFormFillController::MouseDown(Event* aEvent)
|
2003-07-13 06:31:08 +04:00
|
|
|
{
|
2018-04-20 07:49:30 +03:00
|
|
|
MouseEvent* mouseEvent = aEvent->AsMouseEvent();
|
2017-05-17 01:56:28 +03:00
|
|
|
if (!mouseEvent) {
|
2004-07-29 12:42:54 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2017-05-17 01:56:28 +03:00
|
|
|
}
|
2004-07-29 12:42:54 +04:00
|
|
|
|
2018-04-18 23:35:09 +03:00
|
|
|
nsCOMPtr<nsINode> targetNode = do_QueryInterface(aEvent->GetTarget());
|
|
|
|
if (!HTMLInputElement::FromNodeOrNull(targetNode)) {
|
2007-10-02 18:50:51 +04:00
|
|
|
return NS_OK;
|
2017-05-17 01:56:28 +03:00
|
|
|
}
|
2007-10-02 18:50:51 +04:00
|
|
|
|
2018-03-20 07:16:06 +03:00
|
|
|
int16_t button = mouseEvent->Button();
|
2017-04-07 01:01:31 +03:00
|
|
|
|
|
|
|
// In case of a right click we set a timestamp that
|
|
|
|
// will be checked in Focus() to avoid showing
|
|
|
|
// both contextmenu and popup at the same time.
|
|
|
|
if (button == 2) {
|
|
|
|
mLastRightClickTimeStamp = TimeStamp::Now();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-05-17 01:56:28 +03:00
|
|
|
if (button != 0) {
|
2004-07-29 12:42:54 +04:00
|
|
|
return NS_OK;
|
2017-05-17 01:56:28 +03:00
|
|
|
}
|
2004-07-29 12:42:54 +04:00
|
|
|
|
2016-11-21 18:20:44 +03:00
|
|
|
return ShowPopup();
|
|
|
|
}
|
|
|
|
|
2017-02-03 23:44:49 +03:00
|
|
|
NS_IMETHODIMP
|
2016-11-21 18:20:44 +03:00
|
|
|
nsFormFillController::ShowPopup()
|
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isOpen = false;
|
2004-07-29 12:42:54 +04:00
|
|
|
GetPopupOpen(&isOpen);
|
2016-10-24 18:46:16 +03:00
|
|
|
if (isOpen) {
|
|
|
|
return SetPopupOpen(false);
|
|
|
|
}
|
2004-07-29 12:42:54 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIAutoCompleteInput> input;
|
|
|
|
mController->GetInput(getter_AddRefs(input));
|
2017-05-17 01:56:28 +03:00
|
|
|
if (!input) {
|
2003-07-26 06:55:24 +04:00
|
|
|
return NS_OK;
|
2017-05-17 01:56:28 +03:00
|
|
|
}
|
2003-07-26 06:55:24 +04:00
|
|
|
|
2004-07-29 12:42:54 +04:00
|
|
|
nsAutoString value;
|
|
|
|
input->GetTextValue(value);
|
|
|
|
if (value.Length() > 0) {
|
|
|
|
// Show the popup with a filtered result set
|
2005-01-04 22:31:31 +03:00
|
|
|
mController->SetSearchString(EmptyString());
|
2016-09-07 18:44:46 +03:00
|
|
|
bool unused = false;
|
|
|
|
mController->HandleText(&unused);
|
2004-07-29 12:42:54 +04:00
|
|
|
} else {
|
|
|
|
// Show the popup with the complete result set. Can't use HandleText()
|
|
|
|
// because it doesn't display the popup if the input is blank.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool cancel = false;
|
2018-06-26 00:20:54 +03:00
|
|
|
mController->HandleKeyNavigation(KeyboardEvent_Binding::DOM_VK_DOWN, &cancel);
|
2004-07-29 12:42:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2003-07-13 06:31:08 +04:00
|
|
|
}
|
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
//// nsFormFillController
|
|
|
|
|
|
|
|
void
|
2016-01-30 20:05:36 +03:00
|
|
|
nsFormFillController::AddWindowListeners(nsPIDOMWindowOuter* aWindow)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
2017-07-22 01:32:18 +03:00
|
|
|
MOZ_LOG(sLogger, LogLevel::Debug, ("AddWindowListeners for window %p", aWindow));
|
2017-05-17 01:56:28 +03:00
|
|
|
if (!aWindow) {
|
2002-09-28 04:38:20 +04:00
|
|
|
return;
|
2017-05-17 01:56:28 +03:00
|
|
|
}
|
2002-09-28 04:38:20 +04:00
|
|
|
|
2015-10-27 00:37:32 +03:00
|
|
|
EventTarget* target = aWindow->GetChromeEventHandler();
|
2017-05-17 01:56:28 +03:00
|
|
|
if (!target) {
|
2004-07-29 12:42:54 +04:00
|
|
|
return;
|
2017-05-17 01:56:28 +03:00
|
|
|
}
|
2004-07-29 12:42:54 +04:00
|
|
|
|
2018-02-08 16:42:29 +03:00
|
|
|
EventListenerManager* elm = target->GetOrCreateListenerManager();
|
|
|
|
if (NS_WARN_IF(!elm)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
elm->AddEventListenerByType(this, NS_LITERAL_STRING("focus"),
|
|
|
|
TrustedEventsAtCapture());
|
|
|
|
elm->AddEventListenerByType(this, NS_LITERAL_STRING("blur"),
|
|
|
|
TrustedEventsAtCapture());
|
|
|
|
elm->AddEventListenerByType(this, NS_LITERAL_STRING("pagehide"),
|
|
|
|
TrustedEventsAtCapture());
|
|
|
|
elm->AddEventListenerByType(this, NS_LITERAL_STRING("mousedown"),
|
|
|
|
TrustedEventsAtCapture());
|
|
|
|
elm->AddEventListenerByType(this, NS_LITERAL_STRING("input"),
|
|
|
|
TrustedEventsAtCapture());
|
2018-06-22 13:37:09 +03:00
|
|
|
elm->AddEventListenerByType(this, NS_LITERAL_STRING("keydown"),
|
|
|
|
TrustedEventsAtCapture());
|
2018-02-08 16:42:29 +03:00
|
|
|
elm->AddEventListenerByType(this, NS_LITERAL_STRING("keypress"),
|
|
|
|
TrustedEventsAtSystemGroupCapture());
|
|
|
|
elm->AddEventListenerByType(this, NS_LITERAL_STRING("compositionstart"),
|
|
|
|
TrustedEventsAtCapture());
|
|
|
|
elm->AddEventListenerByType(this, NS_LITERAL_STRING("compositionend"),
|
|
|
|
TrustedEventsAtCapture());
|
|
|
|
elm->AddEventListenerByType(this, NS_LITERAL_STRING("contextmenu"),
|
|
|
|
TrustedEventsAtCapture());
|
2009-09-23 10:23:08 +04:00
|
|
|
|
|
|
|
// Note that any additional listeners added should ensure that they ignore
|
|
|
|
// untrusted events, which might be sent by content that's up to no good.
|
2002-09-28 04:38:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-30 20:05:36 +03:00
|
|
|
nsFormFillController::RemoveWindowListeners(nsPIDOMWindowOuter* aWindow)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
2017-07-22 01:32:18 +03:00
|
|
|
MOZ_LOG(sLogger, LogLevel::Debug, ("RemoveWindowListeners for window %p", aWindow));
|
2017-05-17 01:56:28 +03:00
|
|
|
if (!aWindow) {
|
2002-10-02 23:59:08 +04:00
|
|
|
return;
|
2017-05-17 01:56:28 +03:00
|
|
|
}
|
2002-10-02 23:59:08 +04:00
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
StopControllingInput();
|
2011-08-04 04:52:47 +04:00
|
|
|
|
2015-10-27 00:37:32 +03:00
|
|
|
nsCOMPtr<nsIDocument> doc = aWindow->GetDoc();
|
2015-11-25 03:53:46 +03:00
|
|
|
RemoveForDocument(doc);
|
2008-02-27 08:06:13 +03:00
|
|
|
|
2015-10-27 00:37:32 +03:00
|
|
|
EventTarget* target = aWindow->GetChromeEventHandler();
|
2017-05-17 01:56:28 +03:00
|
|
|
if (!target) {
|
2004-07-29 12:42:54 +04:00
|
|
|
return;
|
2017-05-17 01:56:28 +03:00
|
|
|
}
|
2004-07-29 12:42:54 +04:00
|
|
|
|
2018-02-08 16:42:29 +03:00
|
|
|
EventListenerManager* elm = target->GetOrCreateListenerManager();
|
|
|
|
if (NS_WARN_IF(!elm)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
elm->RemoveEventListenerByType(this, NS_LITERAL_STRING("focus"),
|
|
|
|
TrustedEventsAtCapture());
|
|
|
|
elm->RemoveEventListenerByType(this, NS_LITERAL_STRING("blur"),
|
|
|
|
TrustedEventsAtCapture());
|
|
|
|
elm->RemoveEventListenerByType(this, NS_LITERAL_STRING("pagehide"),
|
|
|
|
TrustedEventsAtCapture());
|
|
|
|
elm->RemoveEventListenerByType(this, NS_LITERAL_STRING("mousedown"),
|
|
|
|
TrustedEventsAtCapture());
|
|
|
|
elm->RemoveEventListenerByType(this, NS_LITERAL_STRING("input"),
|
|
|
|
TrustedEventsAtCapture());
|
2018-06-22 13:37:09 +03:00
|
|
|
elm->RemoveEventListenerByType(this, NS_LITERAL_STRING("keydown"),
|
|
|
|
TrustedEventsAtCapture());
|
2018-02-08 16:42:29 +03:00
|
|
|
elm->RemoveEventListenerByType(this, NS_LITERAL_STRING("keypress"),
|
|
|
|
TrustedEventsAtSystemGroupCapture());
|
|
|
|
elm->RemoveEventListenerByType(this, NS_LITERAL_STRING("compositionstart"),
|
|
|
|
TrustedEventsAtCapture());
|
|
|
|
elm->RemoveEventListenerByType(this, NS_LITERAL_STRING("compositionend"),
|
|
|
|
TrustedEventsAtCapture());
|
|
|
|
elm->RemoveEventListenerByType(this, NS_LITERAL_STRING("contextmenu"),
|
|
|
|
TrustedEventsAtCapture());
|
2007-04-04 23:55:04 +04:00
|
|
|
}
|
2002-09-28 04:38:20 +04:00
|
|
|
|
|
|
|
void
|
2018-01-30 08:25:36 +03:00
|
|
|
nsFormFillController::StartControllingInput(HTMLInputElement *aInput)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
2017-07-22 01:32:18 +03:00
|
|
|
MOZ_LOG(sLogger, LogLevel::Verbose, ("StartControllingInput for %p", aInput));
|
2002-09-28 04:38:20 +04:00
|
|
|
// Make sure we're not still attached to an input
|
2011-08-04 04:52:47 +04:00
|
|
|
StopControllingInput();
|
2002-09-28 04:38:20 +04:00
|
|
|
|
2015-01-24 20:37:47 +03:00
|
|
|
if (!mController) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
// Find the currently focused docShell
|
|
|
|
nsCOMPtr<nsIDocShell> docShell = GetDocShellForInput(aInput);
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t index = GetIndexOfDocShell(docShell);
|
2017-05-17 01:56:28 +03:00
|
|
|
if (index < 0) {
|
2002-09-28 04:38:20 +04:00
|
|
|
return;
|
2017-05-17 01:56:28 +03:00
|
|
|
}
|
2011-08-04 04:52:47 +04:00
|
|
|
|
2018-01-30 08:25:36 +03:00
|
|
|
MOZ_ASSERT(aInput, "How did we get a docshell index??");
|
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
// Cache the popup for the focused docShell
|
2012-12-11 01:54:32 +04:00
|
|
|
mFocusedPopup = mPopups.SafeElementAt(index);
|
2011-08-04 04:52:47 +04:00
|
|
|
|
2018-01-30 08:25:36 +03:00
|
|
|
aInput->AddMutationObserverUnlessExists(this);
|
2004-07-29 12:42:54 +04:00
|
|
|
mFocusedInput = aInput;
|
2002-09-28 04:38:20 +04:00
|
|
|
|
2018-01-30 08:25:36 +03:00
|
|
|
Element* list = mFocusedInput->GetList();
|
|
|
|
if (list) {
|
|
|
|
list->AddMutationObserverUnlessExists(this);
|
|
|
|
mListNode = list;
|
2012-02-22 16:59:39 +04:00
|
|
|
}
|
|
|
|
|
2002-09-28 10:25:03 +04:00
|
|
|
mController->SetInput(this);
|
2002-09-28 04:38:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFormFillController::StopControllingInput()
|
|
|
|
{
|
2012-02-22 16:59:39 +04:00
|
|
|
if (mListNode) {
|
|
|
|
mListNode->RemoveMutationObserver(this);
|
2012-07-30 18:20:58 +04:00
|
|
|
mListNode = nullptr;
|
2010-09-10 09:20:16 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 20:37:47 +03:00
|
|
|
if (mController) {
|
|
|
|
// Reset the controller's input, but not if it has been switched
|
|
|
|
// to another input already, which might happen if the user switches
|
|
|
|
// focus by clicking another autocomplete textbox
|
|
|
|
nsCOMPtr<nsIAutoCompleteInput> input;
|
|
|
|
mController->GetInput(getter_AddRefs(input));
|
2017-05-17 01:56:28 +03:00
|
|
|
if (input == this) {
|
2017-07-22 01:32:18 +03:00
|
|
|
MOZ_LOG(sLogger, LogLevel::Verbose,
|
|
|
|
("StopControllingInput: Nulled controller input for %p", this));
|
2015-01-24 20:37:47 +03:00
|
|
|
mController->SetInput(nullptr);
|
2017-05-17 01:56:28 +03:00
|
|
|
}
|
2015-01-24 20:37:47 +03:00
|
|
|
}
|
2002-09-28 04:38:20 +04:00
|
|
|
|
2017-07-22 01:32:18 +03:00
|
|
|
MOZ_LOG(sLogger, LogLevel::Verbose,
|
|
|
|
("StopControllingInput: Stopped controlling %p", mFocusedInput));
|
2018-01-30 08:25:36 +03:00
|
|
|
if (mFocusedInput) {
|
|
|
|
MaybeRemoveMutationObserver(mFocusedInput);
|
2016-03-02 16:34:38 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mFocusedInput = nullptr;
|
2012-02-22 16:59:39 +04:00
|
|
|
}
|
2016-11-21 18:20:44 +03:00
|
|
|
|
|
|
|
if (mFocusedPopup) {
|
|
|
|
mFocusedPopup->ClosePopup();
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
mFocusedPopup = nullptr;
|
2002-09-28 04:38:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIDocShell *
|
2018-01-30 08:25:36 +03:00
|
|
|
nsFormFillController::GetDocShellForInput(HTMLInputElement *aInput)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
2018-01-30 08:25:36 +03:00
|
|
|
NS_ENSURE_TRUE(aInput, nullptr);
|
2014-01-10 06:03:47 +04:00
|
|
|
|
2018-01-30 08:25:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> win = aInput->OwnerDoc()->GetWindow();
|
2014-01-10 06:03:47 +04:00
|
|
|
NS_ENSURE_TRUE(win, nullptr);
|
|
|
|
|
|
|
|
return win->GetDocShell();
|
2002-09-28 04:38:20 +04:00
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowOuter*
|
2002-09-28 04:38:20 +04:00
|
|
|
nsFormFillController::GetWindowForDocShell(nsIDocShell *aDocShell)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContentViewer> contentViewer;
|
|
|
|
aDocShell->GetContentViewer(getter_AddRefs(contentViewer));
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ENSURE_TRUE(contentViewer, nullptr);
|
2002-09-28 04:38:20 +04:00
|
|
|
|
2018-01-31 23:18:09 +03:00
|
|
|
nsCOMPtr<nsIDocument> doc = contentViewer->GetDocument();
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ENSURE_TRUE(doc, nullptr);
|
2002-09-28 04:38:20 +04:00
|
|
|
|
2005-11-29 02:56:44 +03:00
|
|
|
return doc->GetWindow();
|
2002-09-28 04:38:20 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
2002-09-28 04:38:20 +04:00
|
|
|
nsFormFillController::GetIndexOfDocShell(nsIDocShell *aDocShell)
|
|
|
|
{
|
2017-05-17 01:56:28 +03:00
|
|
|
if (!aDocShell) {
|
2005-04-12 02:25:09 +04:00
|
|
|
return -1;
|
2017-05-17 01:56:28 +03:00
|
|
|
}
|
2005-04-12 02:25:09 +04:00
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
// Loop through our cached docShells looking for the given docShell
|
2012-12-11 01:54:32 +04:00
|
|
|
uint32_t count = mDocShells.Length();
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
2017-05-17 01:56:28 +03:00
|
|
|
if (mDocShells[i] == aDocShell) {
|
2002-09-28 04:38:20 +04:00
|
|
|
return i;
|
2017-05-17 01:56:28 +03:00
|
|
|
}
|
2002-09-28 04:38:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Recursively check the parent docShell of this one
|
2018-10-02 00:38:01 +03:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> treeItem = aDocShell;
|
2002-09-28 04:38:20 +04:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentItem;
|
|
|
|
treeItem->GetParent(getter_AddRefs(parentItem));
|
|
|
|
if (parentItem) {
|
|
|
|
nsCOMPtr<nsIDocShell> parentShell = do_QueryInterface(parentItem);
|
|
|
|
return GetIndexOfDocShell(parentShell);
|
|
|
|
}
|
2011-08-04 04:52:47 +04:00
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
return -1;
|
|
|
|
}
|
2006-01-25 23:23:24 +03:00
|
|
|
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFormFillController)
|
|
|
|
|
2010-06-10 22:11:40 +04:00
|
|
|
NS_DEFINE_NAMED_CID(NS_FORMFILLCONTROLLER_CID);
|
|
|
|
|
|
|
|
static const mozilla::Module::CIDEntry kSatchelCIDs[] = {
|
2013-10-11 00:38:05 +04:00
|
|
|
{ &kNS_FORMFILLCONTROLLER_CID, false, nullptr, nsFormFillControllerConstructor },
|
|
|
|
{ nullptr }
|
2010-06-10 22:11:40 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static const mozilla::Module::ContractIDEntry kSatchelContracts[] = {
|
|
|
|
{ "@mozilla.org/satchel/form-fill-controller;1", &kNS_FORMFILLCONTROLLER_CID },
|
|
|
|
{ NS_FORMHISTORYAUTOCOMPLETE_CONTRACTID, &kNS_FORMFILLCONTROLLER_CID },
|
2013-10-11 00:38:05 +04:00
|
|
|
{ nullptr }
|
2010-06-10 22:11:40 +04:00
|
|
|
};
|
2006-01-25 23:23:24 +03:00
|
|
|
|
2010-06-10 22:11:40 +04:00
|
|
|
static const mozilla::Module kSatchelModule = {
|
|
|
|
mozilla::Module::kVersion,
|
|
|
|
kSatchelCIDs,
|
|
|
|
kSatchelContracts
|
2006-01-25 23:23:24 +03:00
|
|
|
};
|
|
|
|
|
2010-06-10 22:11:40 +04:00
|
|
|
NSMODULE_DEFN(satchel) = &kSatchelModule;
|