Bug 1378754 - Add MOZ_LOG logging to nsFormFillController.cpp. r=steveck
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Fri, 21 Jul 2017 15:32:18 -0700
changeset 419654 af4e5e48ca54ae91255fab74c415182268921f31
parent 419653 07bcdde68b57704a17a3c0d4ae3aeb33d687d095
child 419655 b5a0702e2572a8d87541903a11dabd2b238c412e
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssteveck
bugs1378754
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1378754 - Add MOZ_LOG logging to nsFormFillController.cpp. r=steveck MozReview-Commit-ID: KJ7TnnlzrGC
toolkit/components/satchel/nsFormFillController.cpp
--- a/toolkit/components/satchel/nsFormFillController.cpp
+++ b/toolkit/components/satchel/nsFormFillController.cpp
@@ -6,16 +6,17 @@
 
 #include "nsFormFillController.h"
 
 #include "mozilla/ClearOnShutdown.h"
 #include "mozilla/ErrorResult.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent()
 #include "mozilla/dom/HTMLInputElement.h"
+#include "mozilla/Logging.h"
 #include "nsIFormAutoComplete.h"
 #include "nsIInputListAutoComplete.h"
 #include "nsIAutoCompleteSimpleResult.h"
 #include "nsString.h"
 #include "nsReadableUtils.h"
 #include "nsIServiceManager.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsIInterfaceRequestorUtils.h"
@@ -41,16 +42,19 @@
 #include "nsILoadContext.h"
 #include "nsIFrame.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsFocusManager.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 using mozilla::ErrorResult;
+using mozilla::LogLevel;
+
+static mozilla::LazyLogModule sLogger("satchel");
 
 static nsIFormAutoComplete*
 GetFormAutoComplete()
 {
   static nsCOMPtr<nsIFormAutoComplete> sInstance;
   static bool sInitialized = false;
   if (!sInitialized) {
     nsresult rv;
@@ -229,16 +233,17 @@ nsFormFillController::NativeAnonymousChi
 void
 nsFormFillController::ParentChainChanged(nsIContent* aContent)
 {
 }
 
 void
 nsFormFillController::NodeWillBeDestroyed(const nsINode* aNode)
 {
+  MOZ_LOG(sLogger, LogLevel::Verbose, ("NodeWillBeDestroyed: %p", aNode));
   mPwmgrInputs.Remove(aNode);
   mAutofillInputs.Remove(aNode);
   if (aNode == mListNode) {
     mListNode = nullptr;
     RevalidateDataList();
   } else if (aNode == mFocusedInputNode) {
     mFocusedInputNode = nullptr;
     mFocusedInput = nullptr;
@@ -256,16 +261,18 @@ nsFormFillController::MaybeRemoveMutatio
 }
 
 ////////////////////////////////////////////////////////////////////////
 //// nsIFormFillController
 
 NS_IMETHODIMP
 nsFormFillController::AttachToBrowser(nsIDocShell *aDocShell, nsIAutoCompletePopup *aPopup)
 {
+  MOZ_LOG(sLogger, LogLevel::Debug,
+          ("AttachToBrowser for docShell %p with popup %p", aDocShell, aPopup));
   NS_ENSURE_TRUE(aDocShell && aPopup, NS_ERROR_ILLEGAL_VALUE);
 
   mDocShells.AppendElement(aDocShell);
   mPopups.AppendElement(aPopup);
 
   // Listen for focus events on the domWindow of the docShell
   nsCOMPtr<nsPIDOMWindowOuter> window = GetWindowForDocShell(aDocShell);
   AddWindowListeners(window);
@@ -335,16 +342,19 @@ nsFormFillController::MarkAsAutofillFiel
 {
   /*
    * Support other components implementing form autofill and handle autocomplete
    * for the field.
    */
   nsCOMPtr<nsINode> node = do_QueryInterface(aInput);
   NS_ENSURE_STATE(node);
 
+  MOZ_LOG(sLogger, LogLevel::Verbose,
+          ("MarkAsAutofillField: aInput = %p, node = %p", aInput, node.get()));
+
   if (mAutofillInputs.Get(node)) {
     return NS_OK;
   }
 
   mAutofillInputs.Put(node, true);
   node->AddMutationObserverUnlessExists(this);
 
   nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(aInput);
@@ -581,23 +591,25 @@ nsFormFillController::GetSearchCount(uin
   *aSearchCount = 1;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsFormFillController::GetSearchAt(uint32_t index, nsACString & _retval)
 {
   if (mAutofillInputs.Get(mFocusedInputNode)) {
+    MOZ_LOG(sLogger, LogLevel::Debug, ("GetSearchAt: autofill-profiles field"));
     nsCOMPtr<nsIAutoCompleteSearch> profileSearch = do_GetService("@mozilla.org/autocomplete/search;1?name=autofill-profiles");
     if (profileSearch) {
       _retval.AssignLiteral("autofill-profiles");
       return NS_OK;
     }
   }
 
+  MOZ_LOG(sLogger, LogLevel::Debug, ("GetSearchAt: form-history field"));
   _retval.AssignLiteral("form-history");
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsFormFillController::GetTextValue(nsAString & aTextValue)
 {
   if (mFocusedInput) {
@@ -757,25 +769,28 @@ nsFormFillController::GetUserContextId(u
 
 ////////////////////////////////////////////////////////////////////////
 //// nsIAutoCompleteSearch
 
 NS_IMETHODIMP
 nsFormFillController::StartSearch(const nsAString &aSearchString, const nsAString &aSearchParam,
                                   nsIAutoCompleteResult *aPreviousResult, nsIAutoCompleteObserver *aListener)
 {
+  MOZ_LOG(sLogger, LogLevel::Debug, ("StartSearch for %p", mFocusedInput));
+
   nsresult rv;
   nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(mFocusedInputNode);
 
   // If the login manager has indicated it's responsible for this field, let it
   // handle the autocomplete. Otherwise, handle with form history.
   // This method is sometimes called in unit tests and from XUL without a focused node.
   if (mFocusedInputNode &&
       (mPwmgrInputs.Get(mFocusedInputNode) ||
        formControl->ControlType() == NS_FORM_INPUT_PASSWORD)) {
+    MOZ_LOG(sLogger, LogLevel::Debug, ("StartSearch: login field"));
 
     // 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");
     }
 
     if (NS_WARN_IF(!mLoginManager)) {
@@ -786,16 +801,17 @@ nsFormFillController::StartSearch(const 
     // satchel manage the field?
     mLastListener = aListener;
     rv = mLoginManager->AutoCompleteSearchAsync(aSearchString,
                                                 aPreviousResult,
                                                 mFocusedInput,
                                                 this);
     NS_ENSURE_SUCCESS(rv, rv);
   } else {
+    MOZ_LOG(sLogger, LogLevel::Debug, ("StartSearch: non-login field"));
     mLastListener = aListener;
 
     nsCOMPtr<nsIAutoCompleteResult> datalistResult;
     if (mFocusedInput) {
       rv = PerformInputListAutoComplete(aSearchString,
                                         getter_AddRefs(datalistResult));
       NS_ENSURE_SUCCESS(rv, rv);
     }
@@ -1011,16 +1027,17 @@ nsFormFillController::IsTextControl(nsIN
   nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(aNode);
   return formControl &&
          formControl->IsSingleLineTextControl(false);
 }
 
 void
 nsFormFillController::MaybeStartControllingInput(nsIDOMHTMLInputElement* aInput)
 {
+  MOZ_LOG(sLogger, LogLevel::Verbose, ("MaybeStartControllingInput for %p", aInput));
   nsCOMPtr<nsINode> inputNode = do_QueryInterface(aInput);
   if (!inputNode) {
     return;
   }
 
   if (!IsTextControl(inputNode)) {
     return;
   }
@@ -1273,16 +1290,17 @@ nsFormFillController::ShowPopup()
 }
 
 ////////////////////////////////////////////////////////////////////////
 //// nsFormFillController
 
 void
 nsFormFillController::AddWindowListeners(nsPIDOMWindowOuter* aWindow)
 {
+  MOZ_LOG(sLogger, LogLevel::Debug, ("AddWindowListeners for window %p", aWindow));
   if (!aWindow) {
     return;
   }
 
   EventTarget* target = aWindow->GetChromeEventHandler();
 
   if (!target) {
     return;
@@ -1308,16 +1326,17 @@ nsFormFillController::AddWindowListeners
 
   // 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.
 }
 
 void
 nsFormFillController::RemoveWindowListeners(nsPIDOMWindowOuter* aWindow)
 {
+  MOZ_LOG(sLogger, LogLevel::Debug, ("RemoveWindowListeners for window %p", aWindow));
   if (!aWindow) {
     return;
   }
 
   StopControllingInput();
 
   nsCOMPtr<nsIDocument> doc = aWindow->GetDoc();
   RemoveForDocument(doc);
@@ -1339,16 +1358,17 @@ nsFormFillController::RemoveWindowListen
   target->RemoveEventListener(NS_LITERAL_STRING("compositionend"), this,
                               true);
   target->RemoveEventListener(NS_LITERAL_STRING("contextmenu"), this, true);
 }
 
 void
 nsFormFillController::StartControllingInput(nsIDOMHTMLInputElement *aInput)
 {
+  MOZ_LOG(sLogger, LogLevel::Verbose, ("StartControllingInput for %p", aInput));
   // Make sure we're not still attached to an input
   StopControllingInput();
 
   if (!mController) {
     return;
   }
 
   // Find the currently focused docShell
@@ -1391,20 +1411,24 @@ nsFormFillController::StopControllingInp
 
   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));
     if (input == this) {
+      MOZ_LOG(sLogger, LogLevel::Verbose,
+              ("StopControllingInput: Nulled controller input for %p", this));
       mController->SetInput(nullptr);
     }
   }
 
+  MOZ_LOG(sLogger, LogLevel::Verbose,
+          ("StopControllingInput: Stopped controlling %p", mFocusedInput));
   if (mFocusedInputNode) {
     MaybeRemoveMutationObserver(mFocusedInputNode);
 
     mFocusedInputNode = nullptr;
     mFocusedInput = nullptr;
   }
 
   if (mFocusedPopup) {