toolkit/components/satchel/FormHistoryStartup.js

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

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

mercurial