Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 Components.utils.import("resource://gre/modules/PlacesUtils.jsm");
3 /**
4 * Asynchronously adds visits to a page, invoking a callback function when done.
5 *
6 * @param aPlaceInfo
7 * Can be an nsIURI, in such a case a single LINK visit will be added.
8 * Otherwise can be an object describing the visit to add, or an array
9 * of these objects:
10 * { uri: nsIURI of the page,
11 * transition: one of the TRANSITION_* from nsINavHistoryService,
12 * [optional] title: title of the page,
13 * [optional] visitDate: visit date in microseconds from the epoch
14 * [optional] referrer: nsIURI of the referrer for this visit
15 * }
16 * @param [optional] aCallback
17 * Function to be invoked on completion.
18 */
19 function addVisits(aPlaceInfo, aCallback) {
20 let places = [];
21 if (aPlaceInfo instanceof Ci.nsIURI) {
22 places.push({ uri: aPlaceInfo });
23 }
24 else if (Array.isArray(aPlaceInfo)) {
25 places = places.concat(aPlaceInfo);
26 } else {
27 places.push(aPlaceInfo)
28 }
30 // Create mozIVisitInfo for each entry.
31 let now = Date.now();
32 for (let i = 0; i < places.length; i++) {
33 if (!places[i].title) {
34 places[i].title = "test visit for " + places[i].uri.spec;
35 }
36 places[i].visits = [{
37 transitionType: places[i].transition === undefined ? PlacesUtils.history.TRANSITION_LINK
38 : places[i].transition,
39 visitDate: places[i].visitDate || (now++) * 1000,
40 referrerURI: places[i].referrer
41 }];
42 }
44 PlacesUtils.asyncHistory.updatePlaces(
45 places,
46 {
47 handleError: function AAV_handleError() {
48 throw("Unexpected error in adding visit.");
49 },
50 handleResult: function () {},
51 handleCompletion: function UP_handleCompletion() {
52 if (aCallback)
53 aCallback();
54 }
55 }
56 );
57 }