gecko-dev/toolkit/components/satchel/FormHistoryStartup.js
Jared Wein a54eda04ca Bug 1348068 - Enable the key-spacing rule for eslint and fix the related issues. r=standard8
Running eslint with --fix didn't fix many of the issues. The majority here had to be fixed by hand but a significant majority of the issues were related to a few files that I was able to use find-and-replace with. I regret not making this in to separate commits of the hand-fixes and the fixes from --fix but I don't recall --fix fixing any of the issues.

MozReview-Commit-ID: ANyg2qfo3Qx

--HG--
extra : rebase_source : 61d2aa91bf9474af3d72a5dea41b25dca442c1b7
2017-03-21 14:29:43 -04:00

145 lines
4.4 KiB
JavaScript

/* 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/. */
const Cc = Components.classes;
const Ci = Components.interfaces;
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "FormHistory",
"resource://gre/modules/FormHistory.jsm");
function FormHistoryStartup() { }
FormHistoryStartup.prototype = {
classID: Components.ID("{3A0012EB-007F-4BB8-AA81-A07385F77A25}"),
QueryInterface: XPCOMUtils.generateQI([
Ci.nsIObserver,
Ci.nsISupportsWeakReference,
Ci.nsIFrameMessageListener
]),
observe(subject, topic, data) {
switch (topic) {
case "nsPref:changed":
FormHistory.updatePrefs();
break;
case "idle-daily":
case "formhistory-expire-now":
FormHistory.expireOldEntries();
break;
case "profile-before-change":
FormHistory.shutdown();
break;
case "profile-after-change":
this.init();
default:
break;
}
},
inited: false,
pendingQuery: null,
init() {
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);
let messageManager = Cc["@mozilla.org/globalmessagemanager;1"].
getService(Ci.nsIMessageListenerManager);
messageManager.loadFrameScript("chrome://satchel/content/formSubmitListener.js", true);
messageManager.addMessageListener("FormHistory:FormSubmitEntries", this);
// For each of these messages, we could receive them from content,
// or we might receive them from the ppmm if the searchbar is
// having its history queried.
for (let manager of [messageManager, Services.ppmm]) {
manager.addMessageListener("FormHistory:AutoCompleteSearchAsync", this);
manager.addMessageListener("FormHistory:RemoveEntry", this);
}
},
receiveMessage(message) {
switch (message.name) {
case "FormHistory:FormSubmitEntries": {
let entries = message.data;
let changes = entries.map(function(entry) {
return {
op: "bump",
fieldname: entry.name,
value: entry.value,
}
});
FormHistory.update(changes);
break;
}
case "FormHistory:AutoCompleteSearchAsync": {
let { id, searchString, params } = message.data;
if (this.pendingQuery) {
this.pendingQuery.cancel();
this.pendingQuery = null;
}
let mm;
if (message.target instanceof Ci.nsIMessageListenerManager) {
// The target is the PPMM, meaning that the parent process
// is requesting FormHistory data on the searchbar.
mm = message.target;
} else {
// Otherwise, the target is a <xul:browser>.
mm = message.target.messageManager;
}
let results = [];
let processResults = {
handleResult: aResult => {
results.push(aResult);
},
handleCompletion: aReason => {
// Check that the current query is still the one we created. Our
// query might have been canceled shortly before completing, in
// that case we don't want to call the callback anymore.
if (query == this.pendingQuery) {
this.pendingQuery = null;
if (!aReason) {
mm.sendAsyncMessage("FormHistory:AutoCompleteSearchResults",
{ id, results });
}
}
}
};
let query = FormHistory.getAutoCompleteResults(searchString, params,
processResults);
this.pendingQuery = query;
break;
}
case "FormHistory:RemoveEntry": {
let { inputName, value } = message.data;
FormHistory.update({
op: "remove",
fieldname: inputName,
value,
});
break;
}
}
}
};
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([FormHistoryStartup]);