mozilla
Your Search Results

    HomeProvider.jsm

    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: freaktechnik, jdover, leibovic
    Last updated by: freaktechnik,
    Hide Sidebar