Bug 1371131 - Part 4. Hide form autofill footer notes if no warning data in the results. r=seanlee, lchang
MozReview-Commit-ID: AAOEu2JVHnO
--- a/browser/extensions/formautofill/content/formautofill.xml
+++ b/browser/extensions/formautofill/content/formautofill.xml
@@ -164,36 +164,34 @@
);
this._optionButton = document.getAnonymousElementByAttribute(
this, "anonid", "autofill-option-button"
);
this._warningTextBox = document.getAnonymousElementByAttribute(
this, "anonid", "autofill-warning"
);
- let {categories: allFieldCategories, focusedCategory} = JSON.parse(this.getAttribute("ac-value"));
-
/**
* Update the text on the footer.
*
* @private
* @param {string|string[]} categories
* A list of categories that used to generate the message.
* @param {boolean} hasExtraCategories
* Used to determine if it has the extra categories other than the focued category. If
* the value is true, we show "Also fill ...", otherwise, show "Fill ..." only.
*/
- this._updateText = (categories = allFieldCategories, hasExtraCategories = true) => {
+ this._updateText = (categories = this._allFieldCategories, hasExtraCategories = true) => {
let warningTextTmplKey = hasExtraCategories ? "phishingWarningMessage" : "phishingWarningMessage2";
let sep = this._stringBundle.GetStringFromName("fieldNameSeparator");
// Show the categories in certain order to conform with the spec.
let orderedCategoryList = ["address", "name", "organization", "tel", "email"];
let showCategories = hasExtraCategories ?
- orderedCategoryList.filter(category => categories.includes(category) && category != focusedCategory) :
- [focusedCategory];
+ orderedCategoryList.filter(category => categories.includes(category) && category != this._focusedCategory) :
+ [this._focusedCategory];
let categoriesText = showCategories.map(this._stringBundle.GetStringFromName).join(sep);
this._warningTextBox.textContent = this._stringBundle.formatStringFromName(warningTextTmplKey,
[categoriesText], 1);
this.parentNode.parentNode.adjustHeight();
};
/**
@@ -205,39 +203,42 @@
* 3. An address was selected, but the focused category is the same as the only all categories: Only show
* the exact category that we're going to fill in.
*
* @private
* @param {string[]} categories
* The categories of all the fields contained in the selected address.
*/
this._updateWarningMsgHandler = ({data: {categories}} = {data: {}}) => {
- let hasSelectedAddress = focusedCategory && categories;
+ let hasSelectedAddress = this._focusedCategory && categories;
// If the length of categories is 1, that means all the fillable fields are in the same
// category. We will change the way to inform user according to this flag.
let hasExtraCategories = hasSelectedAddress && categories.length > 1;
if (!hasSelectedAddress) {
this._updateText();
return;
}
this._updateText(categories, hasExtraCategories);
};
this._adjustAcItem();
- this._updateText();
]]>
</constructor>
<method name="_onCollapse">
<body>
<![CDATA[
/* global messageManager */
- messageManager.removeMessageListener("FormAutofill:UpdateWarningMessage", this._updateWarningMsgHandler);
+ if (this.showWarningText) {
+ messageManager.removeMessageListener("FormAutofill:UpdateWarningMessage", this._updateWarningMsgHandler);
+ }
+
+ this._itemBox.removeAttribute("no-warning");
]]>
</body>
</method>
<method name="_adjustAcItem">
<body>
<![CDATA[
/* global Cu */
@@ -250,16 +251,28 @@
// If the popup shows up with small layout, we should use short string to
// have a better fit in the box.
if (this._itemBox.getAttribute("size") == "small") {
buttonTextBundleKey += "Short";
}
let buttonText = this._stringBundle.GetStringFromName(buttonTextBundleKey);
this._optionButton.textContent = buttonText;
- messageManager.addMessageListener("FormAutofill:UpdateWarningMessage", this._updateWarningMsgHandler);
+ let value = JSON.parse(this.getAttribute("ac-value"));
+
+ this._allFieldCategories = value.categories;
+ this._focusedCategory = value.focusedCategory;
+ this.showWarningText = this._allFieldCategories && this._focusedCategory;
+
+ if (this.showWarningText) {
+ messageManager.addMessageListener("FormAutofill:UpdateWarningMessage", this._updateWarningMsgHandler);
+
+ this._updateText();
+ } else {
+ this._itemBox.setAttribute("no-warning", "true");
+ }
]]>
</body>
</method>
</implementation>
</binding>
</bindings>
--- a/browser/extensions/formautofill/skin/shared/autocomplete-item.css
+++ b/browser/extensions/formautofill/skin/shared/autocomplete-item.css
@@ -100,8 +100,12 @@ xul|richlistitem[originaltype="autofill-
background-color: rgba(248,232,28,.2);
border-bottom: 1px solid rgba(38,38,38,.15);
}
.autofill-footer > .autofill-option-button {
height: 41px;
background-color: #EDEDED;
}
+
+.autofill-footer[no-warning="true"] > .autofill-warning {
+ display: none;
+}