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