Bug 1330567 - Part 1: Fallback to form history if form autofill pref is disabled, r=MattN

MozReview-Commit-ID: Aq8NhSkxNId

--HG--
extra : rebase_source : 20c4c8aafabcce7c2f4af05c41b3c1989bd9f5d7
This commit is contained in:
steveck-chung 2017-02-08 14:13:59 +08:00
Родитель 559bd6a3a1
Коммит 918291a57e
5 изменённых файлов: 75 добавлений и 12 удалений

Просмотреть файл

@ -1579,6 +1579,7 @@ pref("services.sync.validation.enabled", true);
// Preferences for the form autofill system extension
pref("browser.formautofill.experimental", false);
pref("browser.formautofill.enabled", false);
// Enable safebrowsing v4 tables (suffixed by "-proto") update.
#ifdef NIGHTLY_BUILD

Просмотреть файл

@ -31,6 +31,7 @@
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "OS",
@ -39,10 +40,18 @@ XPCOMUtils.defineLazyModuleGetter(this, "ProfileStorage",
"resource://formautofill/ProfileStorage.jsm");
const PROFILE_JSON_FILE_NAME = "autofill-profiles.json";
const ENABLED_PREF = "browser.formautofill.enabled";
function FormAutofillParent() {
}
FormAutofillParent.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports, Ci.nsIObserver]),
let FormAutofillParent = {
_profileStore: null,
_enabled: false,
/**
* Initializes ProfileStorage and registers the message handler.
*/
@ -53,10 +62,51 @@ let FormAutofillParent = {
this._profileStore = new ProfileStorage(storePath);
this._profileStore.initialize();
let mm = Cc["@mozilla.org/globalmessagemanager;1"]
.getService(Ci.nsIMessageListenerManager);
mm.addMessageListener("FormAutofill:PopulateFieldValues", this);
mm.addMessageListener("FormAutofill:GetProfiles", this);
// Observing the pref (and storage) changes
Services.prefs.addObserver(ENABLED_PREF, this, false);
this._enabled = this._getStatus();
// Force to trigger the onStatusChanged function for setting listeners properly
// while initizlization
this._onStatusChanged();
Services.mm.addMessageListener("FormAutofill:getEnabledStatus", this);
},
/**
* Observe the pref changes and update _enabled cache if status is changed.
*/
observe() {
let currentStatus = this._getStatus();
if (currentStatus !== this._enabled) {
this._enabled = currentStatus;
this._onStatusChanged();
}
},
/**
* Add/remove message listener and broadcast the status to frames while the
* form autofill status changed.
*/
_onStatusChanged() {
if (this._enabled) {
Services.mm.addMessageListener("FormAutofill:PopulateFieldValues", this);
Services.mm.addMessageListener("FormAutofill:GetProfiles", this);
} else {
Services.mm.removeMessageListener("FormAutofill:PopulateFieldValues", this);
Services.mm.removeMessageListener("FormAutofill:GetProfiles", this);
}
Services.mm.broadcastAsyncMessage("FormAutofill:enabledStatus", this._enabled);
},
/**
* Query pref (and storage) status to determine the overall status for
* form autofill feature.
*
* @returns {boolean} status of form autofill feature
*/
_getStatus() {
return Services.prefs.getBoolPref(ENABLED_PREF);
},
/**
@ -74,6 +124,10 @@ let FormAutofillParent = {
case "FormAutofill:GetProfiles":
this._getProfiles(data, target);
break;
case "FormAutofill:getEnabledStatus":
target.messageManager.sendAsyncMessage("FormAutofill:enabledStatus",
this._enabled);
break;
}
},
@ -99,10 +153,8 @@ let FormAutofillParent = {
this._profileStore = null;
}
let mm = Cc["@mozilla.org/globalmessagemanager;1"]
.getService(Ci.nsIMessageListenerManager);
mm.removeMessageListener("FormAutofill:PopulateFieldValues", this);
mm.removeMessageListener("FormAutofill:GetProfiles", this);
Services.mm.removeMessageListener("FormAutofill:PopulateFieldValues", this);
Services.mm.removeMessageListener("FormAutofill:GetProfiles", this);
},
/**

Просмотреть файл

@ -21,7 +21,8 @@ function startup() {
return;
}
FormAutofillParent.init();
let parent = new FormAutofillParent();
parent.init();
Services.mm.loadFrameScript("chrome://formautofill/content/FormAutofillContent.js", true);
}

Просмотреть файл

@ -340,9 +340,16 @@ let ProfileAutocomplete = {
*/
var FormAutofillContent = {
init() {
ProfileAutocomplete.ensureRegistered();
addEventListener("DOMContentLoaded", this);
addMessageListener("FormAutofill:enabledStatus", (result) => {
if (result.data) {
ProfileAutocomplete.ensureRegistered();
} else {
ProfileAutocomplete.ensureUnregistered();
}
});
sendAsyncMessage("FormAutofill:getEnabledStatus");
},
handleEvent(evt) {

Просмотреть файл

@ -40,6 +40,8 @@ let gFileCounter = Math.floor(Math.random() * 1000000);
function loadFormAutofillContent() {
let facGlobal = {
addEventListener() {},
addMessageListener() {},
sendAsyncMessage() {},
};
let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Ci.mozIJSSubScriptLoader);