Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | const Cc = Components.classes; |
michael@0 | 6 | const Ci = Components.interfaces; |
michael@0 | 7 | |
michael@0 | 8 | Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 9 | Components.utils.import("resource://gre/modules/Services.jsm"); |
michael@0 | 10 | |
michael@0 | 11 | XPCOMUtils.defineLazyModuleGetter(this, "FormHistory", |
michael@0 | 12 | "resource://gre/modules/FormHistory.jsm"); |
michael@0 | 13 | |
michael@0 | 14 | XPCOMUtils.defineLazyModuleGetter(this, "AutoCompleteE10S", |
michael@0 | 15 | "resource://gre/modules/AutoCompleteE10S.jsm"); |
michael@0 | 16 | |
michael@0 | 17 | function FormHistoryStartup() { } |
michael@0 | 18 | |
michael@0 | 19 | FormHistoryStartup.prototype = { |
michael@0 | 20 | classID: Components.ID("{3A0012EB-007F-4BB8-AA81-A07385F77A25}"), |
michael@0 | 21 | |
michael@0 | 22 | QueryInterface: XPCOMUtils.generateQI([ |
michael@0 | 23 | Ci.nsIObserver, |
michael@0 | 24 | Ci.nsISupportsWeakReference, |
michael@0 | 25 | Ci.nsIFrameMessageListener |
michael@0 | 26 | ]), |
michael@0 | 27 | |
michael@0 | 28 | observe: function(subject, topic, data) { |
michael@0 | 29 | switch (topic) { |
michael@0 | 30 | case "nsPref:changed": |
michael@0 | 31 | FormHistory.updatePrefs(); |
michael@0 | 32 | break; |
michael@0 | 33 | case "idle-daily": |
michael@0 | 34 | case "formhistory-expire-now": |
michael@0 | 35 | FormHistory.expireOldEntries(); |
michael@0 | 36 | break; |
michael@0 | 37 | case "profile-before-change": |
michael@0 | 38 | FormHistory.shutdown(); |
michael@0 | 39 | break; |
michael@0 | 40 | case "profile-after-change": |
michael@0 | 41 | this.init(); |
michael@0 | 42 | default: |
michael@0 | 43 | break; |
michael@0 | 44 | } |
michael@0 | 45 | }, |
michael@0 | 46 | |
michael@0 | 47 | inited: false, |
michael@0 | 48 | |
michael@0 | 49 | init: function() |
michael@0 | 50 | { |
michael@0 | 51 | if (this.inited) |
michael@0 | 52 | return; |
michael@0 | 53 | this.inited = true; |
michael@0 | 54 | |
michael@0 | 55 | Services.prefs.addObserver("browser.formfill.", this, true); |
michael@0 | 56 | |
michael@0 | 57 | // triggers needed service cleanup and db shutdown |
michael@0 | 58 | Services.obs.addObserver(this, "profile-before-change", true); |
michael@0 | 59 | Services.obs.addObserver(this, "formhistory-expire-now", true); |
michael@0 | 60 | |
michael@0 | 61 | let messageManager = Cc["@mozilla.org/globalmessagemanager;1"]. |
michael@0 | 62 | getService(Ci.nsIMessageListenerManager); |
michael@0 | 63 | messageManager.loadFrameScript("chrome://satchel/content/formSubmitListener.js", true); |
michael@0 | 64 | messageManager.addMessageListener("FormHistory:FormSubmitEntries", this); |
michael@0 | 65 | messageManager.addMessageListener("FormHistory:AutoCompleteSearchAsync", this); |
michael@0 | 66 | }, |
michael@0 | 67 | |
michael@0 | 68 | receiveMessage: function(message) { |
michael@0 | 69 | switch (message.name) { |
michael@0 | 70 | case "FormHistory:FormSubmitEntries": { |
michael@0 | 71 | let entries = message.data; |
michael@0 | 72 | let changes = entries.map(function(entry) { |
michael@0 | 73 | return { |
michael@0 | 74 | op : "bump", |
michael@0 | 75 | fieldname : entry.name, |
michael@0 | 76 | value : entry.value, |
michael@0 | 77 | } |
michael@0 | 78 | }); |
michael@0 | 79 | |
michael@0 | 80 | FormHistory.update(changes); |
michael@0 | 81 | break; |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | case "FormHistory:AutoCompleteSearchAsync": { |
michael@0 | 85 | AutoCompleteE10S.search(message); |
michael@0 | 86 | break; |
michael@0 | 87 | } |
michael@0 | 88 | } |
michael@0 | 89 | } |
michael@0 | 90 | }; |
michael@0 | 91 | |
michael@0 | 92 | this.NSGetFactory = XPCOMUtils.generateNSGetFactory([FormHistoryStartup]); |