B2G/gecko/toolkit/components/places/tests/head_common.js
/**
 * Asynchronously adds visits to a page, invoking a callback function when done.
 *
 * @param aPlaceInfo
 *        Can be an nsIURI, in such a case a single LINK visit will be added.
 *        Otherwise can be an object describing the visit to add, or an array
 *        of these objects:
 *          { uri: nsIURI of the page,
 *            transition: one of the TRANSITION_* from nsINavHistoryService,
 *            [optional] title: title of the page,
 *            [optional] visitDate: visit date in microseconds from the epoch
 *            [optional] referrer: nsIURI of the referrer for this visit
 *          }
 * @param [optional] aCallback
 *        Function to be invoked on completion.
 * @param [optional] aStack
 *        The stack frame used to report errors.
 */
Asynchronously adds visits to a page, invoking a callback function when done.
@param aPlaceInfo
Can be an nsIURI, in such a case a single LINK visit will be added.
Asynchronously adds visits to a page invoking a callback function when done . @param aPlaceInfo Can be an nsIURI in such a case a single LINK visit will be added .
function addVisits(aPlaceInfo, aCallback, aStack)
{
  let stack = aStack || Components.stack.caller;
  let places = [];
  if (aPlaceInfo instanceof Ci.nsIURI) {
    places.push({ uri: aPlaceInfo });
  }
  else if (Array.isArray(aPlaceInfo)) {
    places = places.concat(aPlaceInfo);
  } else {
    places.push(aPlaceInfo)
  }
  let now = Date.now();
  for (let i = 0; i < places.length; i++) {
    if (!places[i].title) {
      places[i].title = "test visit for " + places[i].uri.spec;
    }
    places[i].visits = [{
      transitionType: places[i].transition === undefined ? TRANSITION_LINK
                                                         : places[i].transition,
      visitDate: places[i].visitDate || (now++) * 1000,
      referrerURI: places[i].referrer
    }];
  }
  PlacesUtils.asyncHistory.updatePlaces(
    places,
    {
      handleError: function AAV_handleError() {
        do_throw("Unexpected error in adding visit.", stack);
      },
      handleResult: function () {},
      handleCompletion: function UP_handleCompletion() {
        if (aCallback)
          aCallback();
      }
    }
  );
}
function addVisits ( aPlaceInfo , aCallback , aStack ) { let stack = aStack || Components . stack . caller ; let places = [ ] ; if ( aPlaceInfo instanceof Ci . nsIURI ) { places . push ( { uri : aPlaceInfo } ) ; } else if ( Array . isArray ( aPlaceInfo ) ) { places = places . concat ( aPlaceInfo ) ; } else { places . push ( aPlaceInfo ) } let now = Date . now ( ) ; for ( let i = 0 ; i < places . length ; i ++ ) { if ( ! places [ i ] . title ) { places [ i ] . title = "test visit for " + places [ i ] . uri . spec ; } places [ i ] . visits = [ { transitionType : places [ i ] . transition === undefined ? TRANSITION_LINK : places [ i ] . transition , visitDate : places [ i ] . visitDate || ( now ++ ) * 1000 , referrerURI : places [ i ] . referrer } ] ; } PlacesUtils . asyncHistory . updatePlaces ( places , { handleError : function AAV_handleError ( ) { do_throw ( "Unexpected error in adding visit." , stack ) ; } , handleResult : function ( ) { } , handleCompletion : function UP_handleCompletion ( ) { if ( aCallback ) aCallback ( ) ; } } ) ; }
Asynchronously adds visits to a page, invoking a callback function when done.
Asynchronously adds visits to a page invoking a callback function when done .
// Create mozIVisitInfo for each entry.