HomeProvider.jsm

Add-ons using the techniques described in this document are considered a legacy technology in Firefox. Don't use these techniques to develop new add-ons. Use WebExtensions instead. If you maintain an add-on which uses the techniques described here, consider migrating it to use WebExtensions.

Starting from Firefox 53, no new legacy add-ons will be accepted on addons.mozilla.org (AMO) for desktop Firefox and Firefox for Android.

Starting from Firefox 57, WebExtensions will be the only supported extension type. Desktop Firefox and Firefox for Android will not load other extension types.

Even before Firefox 57, changes coming up in the Firefox platform will break many legacy extensions. These changes include multiprocess Firefox (e10s), sandboxing, and multiple content processes. Legacy extensions that are affected by these changes should migrate to WebExtensions if they can. See the "Compatibility Milestones" document for more information.

A wiki page containing resources, migration paths, office hours, and more, is available to help developers transition to the new technologies.

Summary

The HomeProvider API lets you store data that can be displayed in custom panels on the home page. HomeProvider is a single object that manages access to data and data syncing.

Method Overview

HomeStorage getStorage(in string datasetId)
void requestSync(in string datasetId, function callback)
void addPeriodicSync(in string datasetId, int interval, function callback)
void removePeriodicSync(in string datasetId)

Methods

getStorage()

Retrieves a HomeStorage object for a given dataset.

HomeStorage getStorage(
  in string datasetId
)
Parameters
datasetId
The unique dataset ID.

requestSync()

Calls the sync callback function for the dataset if it's an appropriate time to sync data.

void requestSync(
  in string datasetId,
  in function callback
)
Parameters
datasetId
The unique dataset ID.
callback
Callback function to perform data sync. This function will be called with the datasetId as a parameter.

addPeriodicSync()

Requests sync at the given interval. We limit updates to once per hour, so you will see an error message if you try to sync more frequently than that.

void addPeriodicSync(
  in string datasetId,
  in int interval,
  in function callback
)
Parameters
datasetId
The unique dataset ID.
interval
How frequently to request a sync, in seconds. This should be greater that 3600 (one hour).
callback
Callback function to perform data sync. This function will be called with the datasetId as a parameter.

removePeriodicSync()

Removes periodic sync.

void removePeriodicSync(
  in string datasetId
)
Parameters
datasetId
The unique dataset ID.

Example

Cu.import("resource://gre/modules/HomeProvider.jsm");
Cu.import("resource://gre/modules/Task.jsm");
function syncData() {
  let items = [
    { url: "http://example.com/first",
      title: "First Example" },
    { url: "http://example.com/second",
      title: "Second Example" },
    { url: "filter://folder",
      title: "Folder" },
    { url: "http://example.com/third",
      title: "Filtered Example",
      filter: "folder" }
  ];
  Task.spawn(function() {
    let storage = HomeProvider.getStorage(DATASET_ID);
    // Old way to do replace items in Firefox 30
    // yield storage.deleteAll();
    // yield storage.save(items);
    // New way to replace items in Firefox 31+
    yield storage.save(items, { replace: true });
  });
}
// calls syncData callback once every 3600 seconds (1 hour)
HomeProvider.addPeriodicSync(DATASET_ID, 3600, syncData);

See also

Some demo add-ons are available on Github:

Document Tags and Contributors

 Contributors to this page: rebloor, andrewtruongmoz, wbamberg, freaktechnik, leibovic, jdover
 Last updated by: rebloor,