Bug 1365068 - Added missing brackets & refactored some conditional statements. r=mattn draft
authorJonathan Guillotte-Blouin <jguillotteblouin@mozilla.com>
Tue, 16 May 2017 15:56:28 -0700
changeset 580789 b85b385b99f0
parent 580782 a56f0525bd44
child 580790 5eeb70750e09
push id59664
push userbmo:jguillotteblouin@mozilla.com
push dateThu, 18 May 2017 23:26:04 +0000
reviewersmattn
bugs1365068
milestone55.0a1
Bug 1365068 - Added missing brackets & refactored some conditional statements. r=mattn MozReview-Commit-ID: 1eOkjI06RCJ
toolkit/components/satchel/FormHistory.jsm
toolkit/components/satchel/FormHistoryStartup.js
toolkit/components/satchel/formSubmitListener.js
toolkit/components/satchel/nsFormAutoComplete.js
toolkit/components/satchel/nsFormFillController.cpp
--- a/toolkit/components/satchel/FormHistory.jsm
+++ b/toolkit/components/satchel/FormHistory.jsm
@@ -107,18 +107,19 @@ var supportsDeletedTable = AppConstants.
 var Prefs = {
   initialized: false,
 
   get debug() { this.ensureInitialized(); return this._debug; },
   get enabled() { this.ensureInitialized(); return this._enabled; },
   get expireDays() { this.ensureInitialized(); return this._expireDays; },
 
   ensureInitialized() {
-    if (this.initialized)
+    if (this.initialized) {
       return;
+    }
 
     this.initialized = true;
 
     this._debug = Services.prefs.getBoolPref("browser.formfill.debug");
     this._enabled = Services.prefs.getBoolPref("browser.formfill.enable");
     this._expireDays = Services.prefs.getIntPref("browser.formfill.expire_days");
   }
 };
@@ -229,25 +230,31 @@ function validateSearchData(aData, aData
         aDataType + " query contains an unrecognized field: " + field,
         Cr.NS_ERROR_ILLEGAL_VALUE);
     }
   }
 }
 
 function makeQueryPredicates(aQueryData, delimiter = " AND ") {
   return Object.keys(aQueryData).map(function(field) {
-    if (field == "firstUsedStart") {
-      return "firstUsed >= :" + field;
-    } else if (field == "firstUsedEnd") {
-      return "firstUsed <= :" + field;
-    } else if (field == "lastUsedStart") {
-      return "lastUsed >= :" + field;
-    } else if (field == "lastUsedEnd") {
-      return "lastUsed <= :" + field;
+    switch (field) {
+      case "firstUsedStart": {
+        return "firstUsed >= :" + field;
+      }
+      case "firstUsedEnd": {
+        return "firstUsed <= :" + field;
+      }
+      case "lastUsedStart": {
+        return "lastUsed >= :" + field;
+      }
+      case "lastUsedEnd": {
+        return "lastUsed <= :" + field;
+      }
     }
+
     return field + " = :" + field;
   }).join(delimiter);
 }
 
 /**
  * Storage statement creation and parameter binding
  */
 
@@ -347,18 +354,19 @@ function makeMoveToDeletedStatement(aGui
 
 function generateGUID() {
   // string like: "{f60d9eac-9421-4abc-8491-8e8322b063d4}"
   let uuid = uuidService.generateUUID().toString();
   let raw = ""; // A string with the low bytes set to random values
   let bytes = 0;
   for (let i = 1; bytes < 12 ; i += 2) {
     // Skip dashes
-    if (uuid[i] == "-")
+    if (uuid[i] == "-") {
       i++;
+    }
     let hexVal = parseInt(uuid[i] + uuid[i + 1], 16);
     raw += String.fromCharCode(hexVal);
     bytes++;
   }
   return btoa(raw);
 }
 
 /**
@@ -391,18 +399,19 @@ XPCOMUtils.defineLazyGetter(this, "dbCon
 var dbStmts = new Map();
 
 /*
  * dbCreateAsyncStatement
  *
  * Creates a statement, wraps it, and then does parameter replacement
  */
 function dbCreateAsyncStatement(aQuery, aParams, aBindingArrays) {
-  if (!aQuery)
+  if (!aQuery) {
     return null;
+  }
 
   let stmt = dbStmts.get(aQuery);
   if (!stmt) {
     log("Creating new statement for query: " + aQuery);
     stmt = dbConnection.createAsyncStatement(aQuery);
     dbStmts.set(aQuery, stmt);
   }
 
@@ -628,20 +637,22 @@ function updateFormHistoryWrite(aChanges
   for (let change of aChanges) {
     let operation = change.op;
     delete change.op;
     let stmt;
     switch (operation) {
       case "remove":
         log("Remove from form history  " + change);
         let delStmt = makeMoveToDeletedStatement(change.guid, now, change, bindingArrays);
-        if (delStmt && stmts.indexOf(delStmt) == -1)
+        if (delStmt && stmts.indexOf(delStmt) == -1) {
           stmts.push(delStmt);
-        if ("timeDeleted" in change)
+        }
+        if ("timeDeleted" in change) {
           delete change.timeDeleted;
+        }
         stmt = makeRemoveStatement(change, bindingArrays);
         notifications.push([ "formhistory-remove", change.guid ]);
         break;
       case "update":
         log("Update form history " + change);
         let guid = change.guid;
         delete change.guid;
         // a special case for updating the GUID - the new value can be
@@ -768,17 +779,19 @@ function expireOldEntriesVacuum(aExpireT
 
 this.FormHistory = {
   get enabled() {
     return Prefs.enabled;
   },
 
   search: function formHistorySearch(aSelectTerms, aSearchData, aCallbacks) {
     // if no terms selected, select everything
-    aSelectTerms = (aSelectTerms) ? aSelectTerms : validFields;
+    if (!aSelectTerms) {
+      aSelectTerms = validFields;
+    }
     validateSearchData(aSearchData, "Search");
 
     let stmt = makeSearchStatement(aSearchData, aSelectTerms);
 
     let handlers = {
       handleResult(aResultSet) {
         for (let row = aResultSet.getNextRow(); row; row = aResultSet.getNextRow()) {
           let result = {};
@@ -839,22 +852,23 @@ this.FormHistory = {
   update: function formHistoryUpdate(aChanges, aCallbacks) {
     // Used to keep track of how many searches have been started. When that number
     // are finished, updateFormHistoryWrite can be called.
     let numSearches = 0;
     let completedSearches = 0;
     let searchFailed = false;
 
     function validIdentifier(change) {
-      // The identifier is only valid if one of either the guid or the (fieldname/value) are set
+      // The identifier is only valid if one of either the guid or the (fieldname/value) are set (so an X-OR)
       return Boolean(change.guid) != Boolean(change.fieldname && change.value);
     }
 
-    if (!("length" in aChanges))
+    if (!("length" in aChanges)) {
       aChanges = [aChanges];
+    }
 
     let isRemoveOperation = aChanges.every(change => change && change.op && change.op == "remove");
     if (!Prefs.enabled && !isRemoveOperation) {
       if (aCallbacks && aCallbacks.handleError) {
         aCallbacks.handleError({
           message: "Form history is disabled, only remove operations are allowed",
           result: Ci.mozIStorageError.MISUSE
         });
@@ -1021,18 +1035,19 @@ this.FormHistory = {
                 "FROM moz_formhistory " +
                 "WHERE fieldname=:fieldname " + where +
                 "ORDER BY ROUND(frecency * boundaryBonuses) DESC, UPPER(value) ASC";
 
     let stmt = dbCreateAsyncStatement(query, params);
 
     // Chicken and egg problem: Need the statement to escape the params we
     // pass to the function that gives us the statement. So, fix it up now.
-    if (searchString.length >= 1)
+    if (searchString.length >= 1) {
       stmt.params.valuePrefix = stmt.escapeStringForLIKE(searchString, "/") + "%";
+    }
     if (searchString.length > 1) {
       let searchTokenCount = Math.min(searchTokens.length, MAX_SEARCH_TOKENS);
       for (let i = 0; i < searchTokenCount; i++) {
         let escapedToken = stmt.escapeStringForLIKE(searchTokens[i], "/");
         stmt.params["tokenBegin" + i] = escapedToken + "%";
         stmt.params["tokenBoundary" + i] =  "% " + escapedToken + "%";
         stmt.params["tokenContains" + i] = "%" + escapedToken + "%";
       }
--- a/toolkit/components/satchel/FormHistoryStartup.js
+++ b/toolkit/components/satchel/FormHistoryStartup.js
@@ -40,18 +40,19 @@ FormHistoryStartup.prototype = {
         break;
     }
   },
 
   inited: false,
   pendingQuery: null,
 
   init() {
-    if (this.inited)
+    if (this.inited) {
       return;
+    }
     this.inited = true;
 
     Services.prefs.addObserver("browser.formfill.", this, true);
 
     // triggers needed service cleanup and db shutdown
     Services.obs.addObserver(this, "profile-before-change", true);
     Services.obs.addObserver(this, "formhistory-expire-now", true);
 
--- a/toolkit/components/satchel/formSubmitListener.js
+++ b/toolkit/components/satchel/formSubmitListener.js
@@ -35,39 +35,43 @@ var satchelFormListener = {
 
     // Implements the Luhn checksum algorithm as described at
     // http://wikipedia.org/wiki/Luhn_algorithm
     isValidCCNumber(ccNumber) {
         // Remove dashes and whitespace
         ccNumber = ccNumber.replace(/[\-\s]/g, "");
 
         let len = ccNumber.length;
-        if (len != 9 && len != 15 && len != 16)
+        if (len != 9 && len != 15 && len != 16) {
             return false;
+        }
 
-        if (!/^\d+$/.test(ccNumber))
+        if (!/^\d+$/.test(ccNumber)) {
             return false;
+        }
 
         let total = 0;
         for (let i = 0; i < len; i++) {
             let ch = parseInt(ccNumber[len - i - 1]);
             if (i % 2 == 1) {
                 // Double it, add digits together if > 10
                 ch *= 2;
-                if (ch > 9)
+                if (ch > 9) {
                     ch -= 9;
+                }
             }
             total += ch;
         }
         return total % 10 == 0;
     },
 
     log(message) {
-        if (!this.debug)
+        if (!this.debug) {
             return;
+        }
         dump("satchelFormListener: " + message + "\n");
         Services.console.logStringMessage("satchelFormListener: " + message);
     },
 
     /* ---- nsIObserver interface ---- */
 
     observe(subject, topic, data) {
         if (topic == "nsPref:changed") {
@@ -80,61 +84,65 @@ var satchelFormListener = {
             this.log("Oops! Unexpected notification: " + topic);
         }
     },
 
     /* ---- nsIFormSubmitObserver interfaces ---- */
 
     notify(form, domWin, actionURI, cancelSubmit) {
         try {
-            if (!this.enabled)
+            if (!this.enabled || PrivateBrowsingUtils.isContentWindowPrivate(domWin)) {
                 return;
-
-            if (PrivateBrowsingUtils.isContentWindowPrivate(domWin))
-                return;
+            }
 
             this.log("Form submit observer notified.");
 
             if (form.hasAttribute("autocomplete") &&
-                form.getAttribute("autocomplete").toLowerCase() == "off")
+                form.getAttribute("autocomplete").toLowerCase() == "off") {
                 return;
+            }
 
             let entries = [];
             for (let i = 0; i < form.elements.length; i++) {
                 let input = form.elements[i];
-                if (!(input instanceof Ci.nsIDOMHTMLInputElement))
+                if (!(input instanceof Ci.nsIDOMHTMLInputElement)) {
                     continue;
+                }
 
                 // Only use inputs that hold text values (not including type="password")
-                if (!input.mozIsTextField(true))
+                if (!input.mozIsTextField(true)) {
                     continue;
+                }
 
                 // Bug 394612: If Login Manager marked this input, don't save it.
                 // The login manager will deal with remembering it.
 
                 // Don't save values when autocomplete=off is present.
                 if (input.hasAttribute("autocomplete") &&
-                    input.getAttribute("autocomplete").toLowerCase() == "off")
+                    input.getAttribute("autocomplete").toLowerCase() == "off") {
                     continue;
+                }
 
                 let value = input.value.trim();
 
                 // Don't save empty or unchanged values.
-                if (!value || value == input.defaultValue.trim())
+                if (!value || value == input.defaultValue.trim()) {
                     continue;
+                }
 
                 // Don't save credit card numbers.
                 if (this.isValidCCNumber(value)) {
                     this.log("skipping saving a credit card number");
                     continue;
                 }
 
                 let name = input.name || input.id;
-                if (!name)
+                if (!name) {
                     continue;
+                }
 
                 if (name == "searchbar-history") {
                     this.log('addEntry for input name "' + name + '" is denied')
                     continue;
                 }
 
                 // Limit stored data to 200 characters.
                 if (name.length > 200 || value.length > 200) {
--- a/toolkit/components/satchel/nsFormAutoComplete.js
+++ b/toolkit/components/satchel/nsFormAutoComplete.js
@@ -48,23 +48,21 @@ function FormHistoryClient({ formField, 
         let window = formField.ownerGlobal;
         let topDocShell = window.QueryInterface(Ci.nsIInterfaceRequestor)
                              .getInterface(Ci.nsIDocShell)
                              .sameTypeRootTreeItem
                              .QueryInterface(Ci.nsIDocShell);
         this.mm = topDocShell.QueryInterface(Ci.nsIInterfaceRequestor)
                              .getInterface(Ci.nsIContentFrameMessageManager);
     } else {
-        if (inputName == this.SEARCHBAR_ID) {
-          if (formField) {
-              throw new Error("FormHistoryClient constructed with both a " +
-                              "formField and an inputName. This is not " +
-                              "supported, and only empty results will be " +
-                              "returned.");
-          }
+        if (inputName == this.SEARCHBAR_ID && formField) {
+          throw new Error("FormHistoryClient constructed with both a " +
+                            "formField and an inputName. This is not " +
+                            "supported, and only empty results will be " +
+                            "returned.");
         }
         this.mm = Services.cpmm;
     }
 
     this.inputName = inputName;
     this.id = FormHistoryClient.nextRequestID++;
 }
 
@@ -205,48 +203,49 @@ FormAutoComplete.prototype = {
     observer: {
         _self: null,
 
         QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
                                                Ci.nsISupportsWeakReference]),
 
         observe(subject, topic, data) {
             let self = this._self;
+
             if (topic == "nsPref:changed") {
-                let prefName = data;
-                self.log("got change to " + prefName + " preference");
+              let prefName = data;
+              self.log("got change to " + prefName + " preference");
 
-                switch (prefName) {
-                    case "agedWeight":
-                        self._agedWeight = self._prefBranch.getIntPref(prefName);
-                        break;
-                    case "debug":
-                        self._debug = self._prefBranch.getBoolPref(prefName);
-                        break;
-                    case "enable":
-                        self._enabled = self._prefBranch.getBoolPref(prefName);
-                        break;
-                    case "maxTimeGroupings":
-                        self._maxTimeGroupings = self._prefBranch.getIntPref(prefName);
-                        break;
-                    case "timeGroupingSize":
-                        self._timeGroupingSize = self._prefBranch.getIntPref(prefName) * 1000 * 1000;
-                        break;
-                    case "bucketSize":
-                        self._bucketSize = self._prefBranch.getIntPref(prefName);
-                        break;
-                    case "boundaryWeight":
-                        self._boundaryWeight = self._prefBranch.getIntPref(prefName);
-                        break;
-                    case "prefixWeight":
-                        self._prefixWeight = self._prefBranch.getIntPref(prefName);
-                        break;
-                    default:
-                        self.log("Oops! Pref not handled, change ignored.");
-                }
+              switch (prefName) {
+                  case "agedWeight":
+                      self._agedWeight = self._prefBranch.getIntPref(prefName);
+                      break;
+                  case "debug":
+                      self._debug = self._prefBranch.getBoolPref(prefName);
+                      break;
+                  case "enable":
+                      self._enabled = self._prefBranch.getBoolPref(prefName);
+                      break;
+                  case "maxTimeGroupings":
+                      self._maxTimeGroupings = self._prefBranch.getIntPref(prefName);
+                      break;
+                  case "timeGroupingSize":
+                      self._timeGroupingSize = self._prefBranch.getIntPref(prefName) * 1000 * 1000;
+                      break;
+                  case "bucketSize":
+                      self._bucketSize = self._prefBranch.getIntPref(prefName);
+                      break;
+                  case "boundaryWeight":
+                      self._boundaryWeight = self._prefBranch.getIntPref(prefName);
+                      break;
+                  case "prefixWeight":
+                      self._prefixWeight = self._prefBranch.getIntPref(prefName);
+                      break;
+                  default:
+                      self.log("Oops! Pref not handled, change ignored.");
+              }
             }
         }
     },
 
     // AutoCompleteE10S needs to be able to call autoCompleteSearchAsync without
     // going through IDL in order to pass a mock DOM object field.
     get wrappedJSObject() {
         return this;
@@ -254,18 +253,19 @@ FormAutoComplete.prototype = {
 
     /*
      * log
      *
      * Internal function for logging debug messages to the Error Console
      * window
      */
     log(message) {
-        if (!this._debug)
+        if (!this._debug) {
             return;
+        }
         dump("FormAutoComplete: " + message + "\n");
         Services.console.logStringMessage("FormAutoComplete: " + message);
     },
 
     /*
      * autoCompleteSearchAsync
      *
      * aInputName    -- |name| attribute from the form input being autocompleted.
@@ -373,18 +373,19 @@ FormAutoComplete.prototype = {
             // We have a list of results for a shorter search string, so just
             // filter them further based on the new search string and add to a new array.
             let entries = wrappedResult.entries;
             let filteredEntries = [];
             for (let i = 0; i < entries.length; i++) {
                 let entry = entries[i];
                 // Remove results that do not contain the token
                 // XXX bug 394604 -- .toLowerCase can be wrong for some intl chars
-                if (searchTokens.some(tok => entry.textLowerCase.indexOf(tok) < 0))
+                if (searchTokens.some(tok => entry.textLowerCase.indexOf(tok) < 0)) {
                     continue;
+                }
                 this._calculateScore(entry, searchString, searchTokens);
                 this.log("Reusing autocomplete entry '" + entry.text +
                          "' (" + entry.frecency + " / " + entry.totalScore + ")");
                 filteredEntries.push(entry);
             }
             filteredEntries.sort(sortBytotalScore);
             wrappedResult.entries = filteredEntries;
 
@@ -548,37 +549,40 @@ FormAutoCompleteResult.prototype = {
                                             Ci.nsISupportsWeakReference]),
 
     // private
     client: null,
     entries: null,
     fieldName: null,
 
     _checkIndexBounds(index) {
-        if (index < 0 || index >= this.entries.length)
+        if (index < 0 || index >= this.entries.length) {
             throw Components.Exception("Index out of range.", Cr.NS_ERROR_ILLEGAL_VALUE);
+        }
     },
 
     // Allow autoCompleteSearch to get at the JS object so it can
     // modify some readonly properties for internal use.
     get wrappedJSObject() {
         return this;
     },
 
     // Interfaces from idl...
     searchString: "",
     errorDescription: "",
     get defaultIndex() {
-        if (this.entries.length == 0)
+        if (this.entries.length == 0) {
             return -1;
+        }
         return 0;
     },
     get searchResult() {
-        if (this.entries.length == 0)
+        if (this.entries.length == 0) {
             return Ci.nsIAutoCompleteResult.RESULT_NOMATCH;
+        }
         return Ci.nsIAutoCompleteResult.RESULT_SUCCESS;
     },
     get matchCount() {
         return this.entries.length;
     },
 
     getValueAt(index) {
         this._checkIndexBounds(index);
--- a/toolkit/components/satchel/nsFormFillController.cpp
+++ b/toolkit/components/satchel/nsFormFillController.cpp
@@ -295,18 +295,19 @@ nsFormFillController::MarkAsLoginManager
     if (SameCOMIdentity(focusedContent, node)) {
       nsCOMPtr<nsIDOMHTMLInputElement> input = do_QueryInterface(node);
       if (!mFocusedInput) {
         MaybeStartControllingInput(input);
       }
     }
   }
 
-  if (!mLoginManager)
+  if (!mLoginManager) {
     mLoginManager = do_GetService("@mozilla.org/login-manager;1");
+  }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsFormFillController::MarkAsAutofillField(nsIDOMHTMLInputElement *aInput)
 {
   /*
@@ -362,20 +363,21 @@ nsFormFillController::GetController(nsIA
   *aController = mController;
   NS_IF_ADDREF(*aController);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsFormFillController::GetPopupOpen(bool *aPopupOpen)
 {
-  if (mFocusedPopup)
+  if (mFocusedPopup) {
     mFocusedPopup->GetPopupOpen(aPopupOpen);
-  else
+  } else {
     *aPopupOpen = false;
+  }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsFormFillController::SetPopupOpen(bool aPopupOpen)
 {
   if (mFocusedPopup) {
     if (aPopupOpen) {
@@ -394,18 +396,19 @@ nsFormFillController::SetPopupOpen(bool 
                                          nsIPresShell::SCROLL_MINIMUM,
                                          nsIPresShell::SCROLL_IF_NOT_VISIBLE),
                                        nsIPresShell::SCROLL_OVERFLOW_HIDDEN);
       // mFocusedPopup can be destroyed after ScrollContentIntoView, see bug 420089
       if (mFocusedPopup) {
         nsCOMPtr<nsIDOMElement> element = do_QueryInterface(mFocusedInput);
         mFocusedPopup->OpenAutocompletePopup(this, element);
       }
-    } else
+    } else {
       mFocusedPopup->ClosePopup();
+    }
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsFormFillController::GetDisableAutoComplete(bool *aDisableAutoComplete)
 {
@@ -895,47 +898,53 @@ nsFormFillController::HandleEvent(nsIDOM
     return KeyPress(aEvent);
   }
   if (type.EqualsLiteral("input")) {
     bool unused = false;
     return (!mSuppressOnInput && mController && mFocusedInput) ?
            mController->HandleText(&unused) : NS_OK;
   }
   if (type.EqualsLiteral("blur")) {
-    if (mFocusedInput)
+    if (mFocusedInput) {
       StopControllingInput();
+    }
     return NS_OK;
   }
   if (type.EqualsLiteral("compositionstart")) {
     NS_ASSERTION(mController, "should have a controller!");
-    if (mController && mFocusedInput)
+    if (mController && mFocusedInput) {
       mController->HandleStartComposition();
+    }
     return NS_OK;
   }
   if (type.EqualsLiteral("compositionend")) {
     NS_ASSERTION(mController, "should have a controller!");
-    if (mController && mFocusedInput)
+    if (mController && mFocusedInput) {
       mController->HandleEndComposition();
+    }
     return NS_OK;
   }
   if (type.EqualsLiteral("contextmenu")) {
-    if (mFocusedPopup)
+    if (mFocusedPopup) {
       mFocusedPopup->ClosePopup();
+    }
     return NS_OK;
   }
   if (type.EqualsLiteral("pagehide")) {
 
     nsCOMPtr<nsIDocument> doc = do_QueryInterface(
       aEvent->InternalDOMEvent()->GetTarget());
-    if (!doc)
+    if (!doc) {
       return NS_OK;
+    }
 
     if (mFocusedInput) {
-      if (doc == mFocusedInputNode->OwnerDoc())
+      if (doc == mFocusedInputNode->OwnerDoc()) {
         StopControllingInput();
+      }
     }
 
     RemoveForDocument(doc);
   }
 
   return NS_OK;
 }
 
@@ -966,27 +975,30 @@ nsFormFillController::RemoveForDocument(
     }
   }
 }
 
 void
 nsFormFillController::MaybeStartControllingInput(nsIDOMHTMLInputElement* aInput)
 {
   nsCOMPtr<nsINode> inputNode = do_QueryInterface(aInput);
-  if (!inputNode)
+  if (!inputNode) {
     return;
+  }
 
   nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(aInput);
-  if (!formControl || !formControl->IsSingleLineTextControl(false))
+  if (!formControl || !formControl->IsSingleLineTextControl(false)) {
     return;
+  }
 
   bool isReadOnly = false;
   aInput->GetReadOnly(&isReadOnly);
-  if (isReadOnly)
+  if (isReadOnly) {
     return;
+  }
 
   bool autocomplete = nsContentUtils::IsAutocompleteEnabled(aInput);
 
   nsCOMPtr<nsIDOMHTMLElement> datalist;
   aInput->GetList(getter_AddRefs(datalist));
   bool hasList = datalist != nullptr;
 
   bool isPwmgrInput = false;
@@ -1042,22 +1054,24 @@ nsFormFillController::Focus(nsIDOMEvent*
 
   return NS_OK;
 }
 
 nsresult
 nsFormFillController::KeyPress(nsIDOMEvent* aEvent)
 {
   NS_ASSERTION(mController, "should have a controller!");
-  if (!mFocusedInput || !mController)
+  if (!mFocusedInput || !mController) {
     return NS_OK;
+  }
 
   nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aEvent);
-  if (!keyEvent)
+  if (!keyEvent) {
     return NS_ERROR_FAILURE;
+  }
 
   bool cancel = false;
   bool unused = false;
 
   uint32_t k;
   keyEvent->GetKeyCode(&k);
   switch (k) {
   case nsIDOMKeyEvent::DOM_VK_DELETE:
@@ -1084,18 +1098,19 @@ nsFormFillController::KeyPress(nsIDOMEve
 #endif
   case nsIDOMKeyEvent::DOM_VK_PAGE_UP:
   case nsIDOMKeyEvent::DOM_VK_PAGE_DOWN:
     {
       bool isCtrl, isAlt, isMeta;
       keyEvent->GetCtrlKey(&isCtrl);
       keyEvent->GetAltKey(&isAlt);
       keyEvent->GetMetaKey(&isMeta);
-      if (isCtrl || isAlt || isMeta)
+      if (isCtrl || isAlt || isMeta) {
         break;
+      }
     }
     MOZ_FALLTHROUGH;
   case nsIDOMKeyEvent::DOM_VK_UP:
   case nsIDOMKeyEvent::DOM_VK_DOWN:
   case nsIDOMKeyEvent::DOM_VK_LEFT:
   case nsIDOMKeyEvent::DOM_VK_RIGHT:
     {
       // Get the writing-mode of the relevant input element,
@@ -1154,54 +1169,58 @@ nsFormFillController::KeyPress(nsIDOMEve
 
   return NS_OK;
 }
 
 nsresult
 nsFormFillController::MouseDown(nsIDOMEvent* aEvent)
 {
   nsCOMPtr<nsIDOMMouseEvent> mouseEvent(do_QueryInterface(aEvent));
-  if (!mouseEvent)
+  if (!mouseEvent) {
     return NS_ERROR_FAILURE;
+  }
 
   nsCOMPtr<nsIDOMHTMLInputElement> targetInput = do_QueryInterface(
     aEvent->InternalDOMEvent()->GetTarget());
-  if (!targetInput)
+  if (!targetInput) {
     return NS_OK;
+  }
 
   int16_t button;
   mouseEvent->GetButton(&button);
 
   // 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;
   }
 
-  if (button != 0)
+  if (button != 0) {
     return NS_OK;
+  }
 
   return ShowPopup();
 }
 
 NS_IMETHODIMP
 nsFormFillController::ShowPopup()
 {
   bool isOpen = false;
   GetPopupOpen(&isOpen);
   if (isOpen) {
     return SetPopupOpen(false);
   }
 
   nsCOMPtr<nsIAutoCompleteInput> input;
   mController->GetInput(getter_AddRefs(input));
-  if (!input)
+  if (!input) {
     return NS_OK;
+  }
 
   nsAutoString value;
   input->GetTextValue(value);
   if (value.Length() > 0) {
     // Show the popup with a filtered result set
     mController->SetSearchString(EmptyString());
     bool unused = false;
     mController->HandleText(&unused);
@@ -1216,23 +1235,25 @@ nsFormFillController::ShowPopup()
 }
 
 ////////////////////////////////////////////////////////////////////////
 //// nsFormFillController
 
 void
 nsFormFillController::AddWindowListeners(nsPIDOMWindowOuter* aWindow)
 {
-  if (!aWindow)
+  if (!aWindow) {
     return;
+  }
 
   EventTarget* target = aWindow->GetChromeEventHandler();
 
-  if (!target)
+  if (!target) {
     return;
+  }
 
   target->AddEventListener(NS_LITERAL_STRING("focus"), this,
                            true, false);
   target->AddEventListener(NS_LITERAL_STRING("blur"), this,
                            true, false);
   target->AddEventListener(NS_LITERAL_STRING("pagehide"), this,
                            true, false);
   target->AddEventListener(NS_LITERAL_STRING("mousedown"), this,
@@ -1249,28 +1270,30 @@ 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)
 {
-  if (!aWindow)
+  if (!aWindow) {
     return;
+  }
 
   StopControllingInput();
 
   nsCOMPtr<nsIDocument> doc = aWindow->GetDoc();
   RemoveForDocument(doc);
 
   EventTarget* target = aWindow->GetChromeEventHandler();
 
-  if (!target)
+  if (!target) {
     return;
+  }
 
   target->RemoveEventListener(NS_LITERAL_STRING("focus"), this, true);
   target->RemoveEventListener(NS_LITERAL_STRING("blur"), this, true);
   target->RemoveEventListener(NS_LITERAL_STRING("pagehide"), this, true);
   target->RemoveEventListener(NS_LITERAL_STRING("mousedown"), this, true);
   target->RemoveEventListener(NS_LITERAL_STRING("input"), this, true);
   target->RemoveEventListener(NS_LITERAL_STRING("keypress"), this, true);
   target->RemoveEventListener(NS_LITERAL_STRING("compositionstart"), this,
@@ -1288,18 +1311,19 @@ nsFormFillController::StartControllingIn
 
   if (!mController) {
     return;
   }
 
   // Find the currently focused docShell
   nsCOMPtr<nsIDocShell> docShell = GetDocShellForInput(aInput);
   int32_t index = GetIndexOfDocShell(docShell);
-  if (index < 0)
+  if (index < 0) {
     return;
+  }
 
   // Cache the popup for the focused docShell
   mFocusedPopup = mPopups.SafeElementAt(index);
 
   nsCOMPtr<nsINode> node = do_QueryInterface(aInput);
   if (!node) {
     return;
   }
@@ -1328,18 +1352,19 @@ 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)
+    if (input == this) {
       mController->SetInput(nullptr);
+    }
   }
 
   if (mFocusedInputNode) {
     MaybeRemoveMutationObserver(mFocusedInputNode);
 
     nsresult rv;
     nsCOMPtr <nsIFormAutoComplete> formAutoComplete =
       do_GetService("@mozilla.org/satchel/form-autocomplete;1", &rv);
@@ -1382,24 +1407,26 @@ nsFormFillController::GetWindowForDocShe
   NS_ENSURE_TRUE(doc, nullptr);
 
   return doc->GetWindow();
 }
 
 int32_t
 nsFormFillController::GetIndexOfDocShell(nsIDocShell *aDocShell)
 {
-  if (!aDocShell)
+  if (!aDocShell) {
     return -1;
+  }
 
   // Loop through our cached docShells looking for the given docShell
   uint32_t count = mDocShells.Length();
   for (uint32_t i = 0; i < count; ++i) {
-    if (mDocShells[i] == aDocShell)
+    if (mDocShells[i] == aDocShell) {
       return i;
+    }
   }
 
   // Recursively check the parent docShell of this one
   nsCOMPtr<nsIDocShellTreeItem> treeItem = do_QueryInterface(aDocShell);
   nsCOMPtr<nsIDocShellTreeItem> parentItem;
   treeItem->GetParent(getter_AddRefs(parentItem));
   if (parentItem) {
     nsCOMPtr<nsIDocShell> parentShell = do_QueryInterface(parentItem);