2008-06-27 01:49:01 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
2008-12-09 23:26:14 +03:00
|
|
|
* The Original Code is Weave
|
2008-06-27 01:49:01 +04:00
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Mozilla.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2008
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Dan Mills <thunder@mozilla.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2008-06-04 00:56:16 +04:00
|
|
|
const EXPORTED_SYMBOLS = ['HistoryEngine'];
|
|
|
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
|
2008-12-17 13:32:00 +03:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
|
2008-06-04 00:56:16 +04:00
|
|
|
Cu.import("resource://weave/log4moz.js");
|
|
|
|
Cu.import("resource://weave/util.js");
|
|
|
|
Cu.import("resource://weave/engines.js");
|
|
|
|
Cu.import("resource://weave/stores.js");
|
|
|
|
Cu.import("resource://weave/trackers.js");
|
2008-06-11 21:40:24 +04:00
|
|
|
Cu.import("resource://weave/async.js");
|
2009-03-31 02:19:00 +04:00
|
|
|
Cu.import("resource://weave/base_records/collection.js");
|
2009-01-03 12:04:17 +03:00
|
|
|
Cu.import("resource://weave/type_records/history.js");
|
2008-06-11 21:40:24 +04:00
|
|
|
|
|
|
|
Function.prototype.async = Async.sugar;
|
2008-06-04 00:56:16 +04:00
|
|
|
|
2008-12-09 23:26:14 +03:00
|
|
|
function HistoryEngine() {
|
|
|
|
this._init();
|
2008-06-04 00:56:16 +04:00
|
|
|
}
|
|
|
|
HistoryEngine.prototype = {
|
2008-12-09 23:26:14 +03:00
|
|
|
__proto__: SyncEngine.prototype,
|
2009-01-07 00:54:18 +03:00
|
|
|
name: "history",
|
|
|
|
displayName: "History",
|
|
|
|
logName: "History",
|
2009-04-13 23:54:31 +04:00
|
|
|
_recordObj: HistoryRec,
|
2009-01-07 00:54:18 +03:00
|
|
|
_storeObj: HistoryStore,
|
2009-01-16 01:05:50 +03:00
|
|
|
_trackerObj: HistoryTracker,
|
2009-01-21 00:13:31 +03:00
|
|
|
|
|
|
|
// History reconciliation is simpler than the default one from SyncEngine,
|
|
|
|
// because we have the advantage that we can use the URI as a definitive
|
|
|
|
// check for local existence of incoming items. The steps are as follows:
|
2009-01-28 04:08:47 +03:00
|
|
|
//
|
2009-01-21 00:13:31 +03:00
|
|
|
// 1) Check for the same item in the locally modified list. In that case,
|
|
|
|
// local trumps remote. This step is unchanged from our superclass.
|
|
|
|
// 2) Check if the incoming item was deleted. Skip if so.
|
|
|
|
// 3) Apply new record/update.
|
2009-01-28 04:08:47 +03:00
|
|
|
//
|
2009-01-21 00:13:31 +03:00
|
|
|
// Note that we don't attempt to equalize the IDs, the history store does that
|
|
|
|
// as part of update()
|
|
|
|
_reconcile: function HistEngine__reconcile(item) {
|
2009-01-16 01:05:50 +03:00
|
|
|
let self = yield;
|
2009-01-21 00:13:31 +03:00
|
|
|
let ret = true;
|
|
|
|
|
|
|
|
// Step 1: Check for conflicts
|
|
|
|
// If same as local record, do not upload
|
|
|
|
if (item.id in this._tracker.changedIDs) {
|
|
|
|
if (this._isEqual(item))
|
|
|
|
this._tracker.removeChangedID(item.id);
|
|
|
|
self.done(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Step 2: Check if the item is deleted - we don't support that (yet?)
|
2009-04-03 21:38:47 +04:00
|
|
|
if (item.deleted) {
|
2009-01-21 00:13:31 +03:00
|
|
|
self.done(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Step 3: Apply update/new record
|
|
|
|
self.done(true);
|
2009-03-31 02:19:00 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
_syncFinish: function HistEngine__syncFinish(error) {
|
|
|
|
let self = yield;
|
|
|
|
this._log.debug("Finishing up sync");
|
|
|
|
this._tracker.resetScore();
|
|
|
|
|
|
|
|
// Only leave 1 week's worth of history on the server
|
|
|
|
let coll = new Collection(this.engineURL, this._recordObj);
|
|
|
|
coll.older = this.lastSync - 604800; // 1 week
|
|
|
|
coll.full = 0;
|
|
|
|
yield coll.delete(self.cb);
|
2009-01-16 01:05:50 +03:00
|
|
|
}
|
2008-06-04 00:56:16 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
function HistoryStore() {
|
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
HistoryStore.prototype = {
|
2008-12-09 23:26:14 +03:00
|
|
|
__proto__: Store.prototype,
|
2008-06-04 00:56:16 +04:00
|
|
|
_logName: "HistStore",
|
|
|
|
|
|
|
|
get _hsvc() {
|
2008-12-09 23:26:14 +03:00
|
|
|
let hsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
|
|
|
|
getService(Ci.nsINavHistoryService);
|
|
|
|
hsvc.QueryInterface(Ci.nsIGlobalHistory2);
|
|
|
|
hsvc.QueryInterface(Ci.nsIBrowserHistory);
|
2008-12-10 11:57:27 +03:00
|
|
|
hsvc.QueryInterface(Ci.nsPIPlacesDatabase);
|
2008-12-09 23:26:14 +03:00
|
|
|
this.__defineGetter__("_hsvc", function() hsvc);
|
|
|
|
return hsvc;
|
2008-06-04 00:56:16 +04:00
|
|
|
},
|
|
|
|
|
2008-12-10 11:57:27 +03:00
|
|
|
get _anno() {
|
|
|
|
let anno = Cc["@mozilla.org/browser/annotation-service;1"].
|
|
|
|
getService(Ci.nsIAnnotationService);
|
|
|
|
this.__defineGetter__("_ans", function() anno);
|
|
|
|
return anno;
|
|
|
|
},
|
|
|
|
|
|
|
|
get _histDB_30() {
|
2008-12-09 23:26:14 +03:00
|
|
|
let file = Cc["@mozilla.org/file/directory_service;1"].
|
|
|
|
getService(Ci.nsIProperties).
|
|
|
|
get("ProfD", Ci.nsIFile);
|
|
|
|
file.append("places.sqlite");
|
|
|
|
let stor = Cc["@mozilla.org/storage/service;1"].
|
|
|
|
getService(Ci.mozIStorageService);
|
|
|
|
let db = stor.openDatabase(file);
|
2008-12-10 11:57:27 +03:00
|
|
|
this.__defineGetter__("_histDB_30", function() db);
|
2008-12-09 23:26:14 +03:00
|
|
|
return db;
|
2008-08-08 07:00:35 +04:00
|
|
|
},
|
|
|
|
|
2008-12-10 11:57:27 +03:00
|
|
|
get _db() {
|
2008-12-27 08:50:07 +03:00
|
|
|
return this._hsvc.DBConnection;
|
2008-12-10 11:57:27 +03:00
|
|
|
},
|
|
|
|
|
2008-12-18 03:04:03 +03:00
|
|
|
_fetchRow: function HistStore__fetchRow(stm, params, retparams) {
|
|
|
|
try {
|
|
|
|
for (let key in params) {
|
|
|
|
stm.params[key] = params[key];
|
|
|
|
}
|
|
|
|
if (!stm.step())
|
|
|
|
return null;
|
|
|
|
if (retparams.length == 1)
|
|
|
|
return stm.row[retparams[0]];
|
|
|
|
let ret = {};
|
|
|
|
for each (let key in retparams) {
|
|
|
|
ret[key] = stm.row[key];
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
} finally {
|
|
|
|
stm.reset();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-01-21 00:13:31 +03:00
|
|
|
// Check for table existance manually because
|
|
|
|
// mozIStorageConnection.tableExists() gives us false negatives
|
|
|
|
tableExists: function HistStore__tableExists(tableName) {
|
2009-01-16 01:05:50 +03:00
|
|
|
let statement = this._db.createStatement(
|
|
|
|
"SELECT count(*) as count FROM sqlite_temp_master WHERE type='table' " +
|
2009-01-21 00:13:31 +03:00
|
|
|
"AND name='" + tableName + "'");
|
2009-01-16 01:05:50 +03:00
|
|
|
statement.step();
|
|
|
|
let num = statement.row["count"];
|
2009-01-21 00:13:31 +03:00
|
|
|
return num != 0;
|
2009-01-16 01:05:50 +03:00
|
|
|
},
|
|
|
|
|
2008-12-10 11:57:27 +03:00
|
|
|
get _visitStm() {
|
2008-12-20 04:00:12 +03:00
|
|
|
this._log.trace("Creating SQL statement: _visitStm");
|
2009-01-10 02:44:27 +03:00
|
|
|
let stm;
|
2009-01-21 00:13:31 +03:00
|
|
|
if (this.tableExists("moz_historyvisits_temp")) {
|
2009-01-10 02:44:27 +03:00
|
|
|
stm = this._db.createStatement(
|
|
|
|
"SELECT * FROM ( " +
|
|
|
|
"SELECT visit_type AS type, visit_date AS date " +
|
|
|
|
"FROM moz_historyvisits_temp " +
|
|
|
|
"WHERE place_id = :placeid " +
|
|
|
|
"ORDER BY visit_date DESC " +
|
|
|
|
"LIMIT 10 " +
|
|
|
|
") " +
|
|
|
|
"UNION ALL " +
|
|
|
|
"SELECT * FROM ( " +
|
|
|
|
"SELECT visit_type AS type, visit_date AS date " +
|
|
|
|
"FROM moz_historyvisits " +
|
|
|
|
"WHERE place_id = :placeid " +
|
|
|
|
"AND id NOT IN (SELECT id FROM moz_historyvisits_temp) " +
|
|
|
|
"ORDER BY visit_date DESC " +
|
|
|
|
"LIMIT 10 " +
|
|
|
|
") " +
|
|
|
|
"ORDER BY 2 DESC LIMIT 10"); /* 2 is visit_date */
|
|
|
|
} else {
|
|
|
|
stm = this._db.createStatement(
|
|
|
|
"SELECT visit_type AS type, visit_date AS date " +
|
|
|
|
"FROM moz_historyvisits " +
|
|
|
|
"WHERE place_id = :placeid " +
|
|
|
|
"ORDER BY visit_date DESC LIMIT 10"
|
|
|
|
);
|
|
|
|
}
|
2008-12-20 04:00:12 +03:00
|
|
|
this.__defineGetter__("_visitStm", function() stm);
|
2008-12-18 03:04:03 +03:00
|
|
|
return stm;
|
2008-12-10 11:57:27 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
get _pidStm() {
|
2008-12-20 04:00:12 +03:00
|
|
|
this._log.trace("Creating SQL statement: _pidStm");
|
2009-01-10 02:44:27 +03:00
|
|
|
let stm;
|
|
|
|
// See comment in get _urlStm()
|
2009-01-21 00:13:31 +03:00
|
|
|
if (this.tableExists("moz_places_temp")) {
|
2009-01-10 02:44:27 +03:00
|
|
|
stm = this._db.createStatement(
|
|
|
|
"SELECT * FROM " +
|
|
|
|
"(SELECT id FROM moz_places_temp WHERE url = :url LIMIT 1) " +
|
|
|
|
"UNION ALL " +
|
|
|
|
"SELECT * FROM ( " +
|
|
|
|
"SELECT id FROM moz_places WHERE url = :url " +
|
|
|
|
"AND id NOT IN (SELECT id from moz_places_temp) " +
|
|
|
|
"LIMIT 1 " +
|
|
|
|
") " +
|
|
|
|
"LIMIT 1");
|
|
|
|
} else {
|
|
|
|
stm = this._db.createStatement(
|
|
|
|
"SELECT id FROM moz_places WHERE url = :url LIMIT 1"
|
|
|
|
);
|
|
|
|
}
|
2008-12-20 04:00:12 +03:00
|
|
|
this.__defineGetter__("_pidStm", function() stm);
|
2008-12-18 03:04:03 +03:00
|
|
|
return stm;
|
2008-12-10 11:57:27 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
get _urlStm() {
|
2008-12-20 04:00:12 +03:00
|
|
|
this._log.trace("Creating SQL statement: _urlStm");
|
2009-01-10 02:44:27 +03:00
|
|
|
/* On Fennec, there is no table called moz_places_temp.
|
|
|
|
* (We think there should be; we're not sure why there's not.)
|
|
|
|
* As a workaround until we figure out why, we'll check if the table
|
|
|
|
* exists first, and if it doesn't we'll use a simpler query without
|
|
|
|
* that table.
|
|
|
|
*/
|
|
|
|
let stm;
|
2009-01-21 00:13:31 +03:00
|
|
|
if (this.tableExists("moz_places_temp")) {
|
2009-01-10 02:44:27 +03:00
|
|
|
stm = this._db.createStatement(
|
2008-12-19 09:39:32 +03:00
|
|
|
"SELECT * FROM " +
|
2009-01-03 12:04:17 +03:00
|
|
|
"(SELECT url,title FROM moz_places_temp WHERE id = :id LIMIT 1) " +
|
2008-12-19 09:39:32 +03:00
|
|
|
"UNION ALL " +
|
|
|
|
"SELECT * FROM ( " +
|
2009-01-03 12:04:17 +03:00
|
|
|
"SELECT url,title FROM moz_places WHERE id = :id " +
|
2008-12-19 09:39:32 +03:00
|
|
|
"AND id NOT IN (SELECT id from moz_places_temp) " +
|
|
|
|
"LIMIT 1 " +
|
|
|
|
") " +
|
|
|
|
"LIMIT 1");
|
2009-01-10 02:44:27 +03:00
|
|
|
} else {
|
|
|
|
stm = this._db.createStatement(
|
|
|
|
"SELECT url,title FROM moz_places WHERE id = :id LIMIT 1"
|
|
|
|
);
|
2009-01-09 03:37:36 +03:00
|
|
|
}
|
2008-12-20 04:00:12 +03:00
|
|
|
this.__defineGetter__("_urlStm", function() stm);
|
2008-12-18 03:04:03 +03:00
|
|
|
return stm;
|
2008-12-10 11:57:27 +03:00
|
|
|
},
|
|
|
|
|
2008-12-17 13:32:00 +03:00
|
|
|
get _annoAttrIdStm() {
|
2008-12-20 04:00:12 +03:00
|
|
|
this._log.trace("Creating SQL statement: _annoAttrIdStm");
|
|
|
|
let stm = this._db.createStatement(
|
2008-12-17 13:32:00 +03:00
|
|
|
"SELECT id from moz_anno_attributes WHERE name = :name");
|
2008-12-20 04:00:12 +03:00
|
|
|
this.__defineGetter__("_annoAttrIdStm", function() stm);
|
2008-12-18 03:04:03 +03:00
|
|
|
return stm;
|
2008-12-17 13:32:00 +03:00
|
|
|
},
|
|
|
|
|
2008-12-10 11:57:27 +03:00
|
|
|
get _findPidByAnnoStm() {
|
2008-12-20 04:00:12 +03:00
|
|
|
this._log.trace("Creating SQL statement: _findPidByAnnoStm");
|
|
|
|
let stm = this._db.createStatement(
|
2008-12-18 03:04:03 +03:00
|
|
|
"SELECT place_id AS id FROM moz_annos " +
|
|
|
|
"WHERE anno_attribute_id = :attr AND content = :content");
|
2008-12-20 04:00:12 +03:00
|
|
|
this.__defineGetter__("_findPidByAnnoStm", function() stm);
|
2008-12-18 03:04:03 +03:00
|
|
|
return stm;
|
2008-06-04 00:56:16 +04:00
|
|
|
},
|
|
|
|
|
2008-12-10 11:57:27 +03:00
|
|
|
// See bug 320831 for why we use SQL here
|
2008-12-18 03:04:03 +03:00
|
|
|
_getVisits: function HistStore__getVisits(uri) {
|
2008-12-19 09:39:32 +03:00
|
|
|
let visits = [];
|
2008-12-13 00:55:58 +03:00
|
|
|
if (typeof(uri) != "string")
|
|
|
|
uri = uri.spec;
|
2008-12-19 09:39:32 +03:00
|
|
|
|
2008-12-18 03:04:03 +03:00
|
|
|
let placeid = this._fetchRow(this._pidStm, {url: uri}, ['id']);
|
2008-12-19 09:39:32 +03:00
|
|
|
if (!placeid) {
|
|
|
|
this._log.debug("Could not find place ID for history URL: " + placeid);
|
|
|
|
return visits;
|
|
|
|
}
|
2008-12-18 03:04:03 +03:00
|
|
|
|
2008-12-20 04:00:12 +03:00
|
|
|
try {
|
|
|
|
this._visitStm.params.placeid = placeid;
|
|
|
|
while (this._visitStm.step()) {
|
|
|
|
visits.push({date: this._visitStm.row.date,
|
|
|
|
type: this._visitStm.row.type});
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
this._visitStm.reset();
|
2008-12-10 11:57:27 +03:00
|
|
|
}
|
2008-12-20 04:00:12 +03:00
|
|
|
|
2008-12-18 03:04:03 +03:00
|
|
|
return visits;
|
2008-06-04 00:56:16 +04:00
|
|
|
},
|
|
|
|
|
2008-12-13 00:55:58 +03:00
|
|
|
_getGUID: function HistStore__getGUID(uri) {
|
|
|
|
if (typeof(uri) == "string")
|
|
|
|
uri = Utils.makeURI(uri);
|
2008-12-10 11:57:27 +03:00
|
|
|
try {
|
|
|
|
return this._anno.getPageAnnotation(uri, "weave/guid");
|
|
|
|
} catch (e) {
|
|
|
|
// FIXME
|
|
|
|
// if (e != NS_ERROR_NOT_AVAILABLE)
|
|
|
|
// throw e;
|
2008-08-08 07:00:35 +04:00
|
|
|
}
|
2008-12-10 11:57:27 +03:00
|
|
|
let guid = Utils.makeGUID();
|
2008-12-17 13:32:00 +03:00
|
|
|
this._anno.setPageAnnotation(uri, "weave/guid", guid, 0, this._anno.EXPIRE_WITH_HISTORY);
|
2008-12-10 11:57:27 +03:00
|
|
|
return guid;
|
|
|
|
},
|
2008-08-08 07:00:35 +04:00
|
|
|
|
2008-12-10 11:57:27 +03:00
|
|
|
// See bug 468732 for why we use SQL here
|
2008-12-20 04:00:12 +03:00
|
|
|
_findURLByGUID: function HistStore__findURLByGUID(guid) {
|
2008-12-17 13:32:00 +03:00
|
|
|
try {
|
|
|
|
this._annoAttrIdStm.params.name = "weave/guid";
|
|
|
|
if (!this._annoAttrIdStm.step())
|
|
|
|
return null;
|
|
|
|
let annoId = this._annoAttrIdStm.row.id;
|
|
|
|
|
|
|
|
this._findPidByAnnoStm.params.attr = annoId;
|
|
|
|
this._findPidByAnnoStm.params.content = guid;
|
|
|
|
if (!this._findPidByAnnoStm.step())
|
|
|
|
return null;
|
|
|
|
let placeId = this._findPidByAnnoStm.row.id;
|
|
|
|
|
|
|
|
this._urlStm.params.id = placeId;
|
|
|
|
if (!this._urlStm.step())
|
|
|
|
return null;
|
|
|
|
|
2009-01-03 12:04:17 +03:00
|
|
|
return {url: this._urlStm.row.url,
|
|
|
|
title: this._urlStm.row.title};
|
2008-12-17 13:32:00 +03:00
|
|
|
} finally {
|
|
|
|
this._annoAttrIdStm.reset();
|
|
|
|
this._findPidByAnnoStm.reset();
|
|
|
|
this._urlStm.reset();
|
2008-08-08 07:00:35 +04:00
|
|
|
}
|
2008-12-17 13:32:00 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
changeItemID: function HStore_changeItemID(oldID, newID) {
|
2009-01-08 02:01:12 +03:00
|
|
|
try {
|
2009-01-16 05:43:44 +03:00
|
|
|
let uri = Utils.makeURI(this._findURLByGUID(oldID).url);
|
2009-01-08 02:01:12 +03:00
|
|
|
this._anno.setPageAnnotation(uri, "weave/guid", newID, 0, 0);
|
|
|
|
} catch (e) {
|
|
|
|
this._log.debug("Could not change item ID: " + e);
|
|
|
|
}
|
2008-08-08 07:00:35 +04:00
|
|
|
},
|
2008-12-10 11:57:27 +03:00
|
|
|
|
2009-01-03 12:04:17 +03:00
|
|
|
|
|
|
|
getAllIDs: function HistStore_getAllIDs() {
|
|
|
|
let query = this._hsvc.getNewQuery(),
|
|
|
|
options = this._hsvc.getNewQueryOptions();
|
|
|
|
|
|
|
|
query.minVisits = 1;
|
|
|
|
options.maxResults = 100;
|
2009-02-05 06:51:20 +03:00
|
|
|
/*
|
|
|
|
dump("SORT_BY_DATE_DESCENDING is " + options.SORT_BY_DATE_DESCENDING + "\n");
|
|
|
|
dump("SORT_BY_ANNOTATIOn_DESCENDING is " + options.SORT_BY_ANNOTATION_DESCENDING + "\n");
|
|
|
|
dump("BEFORE SETTING, options.sortingMode is " + options.sortingMode + "\n");
|
|
|
|
|
|
|
|
for ( let z = -1; z < 20; z++) {
|
|
|
|
try {
|
|
|
|
options.sortingMode = z;
|
|
|
|
dump(" -> Can set to " + z + " OK...\n");
|
|
|
|
} catch (e) {
|
|
|
|
dump(" -> Setting to " + z + " raises exception.\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dump("AFTER SETTING, options.sortingMode is " + options.sortingMode + "\n");
|
|
|
|
*/
|
|
|
|
// TODO the following line throws exception on Fennec; see above.
|
2009-01-03 12:04:17 +03:00
|
|
|
options.sortingMode = options.SORT_BY_DATE_DESCENDING;
|
|
|
|
options.queryType = options.QUERY_TYPE_HISTORY;
|
|
|
|
|
|
|
|
let root = this._hsvc.executeQuery(query, options).root;
|
|
|
|
root.QueryInterface(Ci.nsINavHistoryQueryResultNode);
|
|
|
|
root.containerOpen = true;
|
|
|
|
|
|
|
|
let items = {};
|
|
|
|
for (let i = 0; i < root.childCount; i++) {
|
|
|
|
let item = root.getChild(i);
|
|
|
|
let guid = this._getGUID(item.uri);
|
|
|
|
items[guid] = item.uri;
|
|
|
|
}
|
|
|
|
return items;
|
2008-12-13 00:55:58 +03:00
|
|
|
},
|
|
|
|
|
2008-12-18 03:04:03 +03:00
|
|
|
create: function HistStore_create(record) {
|
2009-01-21 00:13:31 +03:00
|
|
|
this.update(record);
|
2008-12-18 03:04:03 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
remove: function HistStore_remove(record) {
|
2009-01-21 00:13:31 +03:00
|
|
|
//this._log.trace(" -> NOT removing history entry: " + record.id);
|
2008-12-18 03:04:03 +03:00
|
|
|
// FIXME: implement!
|
|
|
|
},
|
|
|
|
|
|
|
|
update: function HistStore_update(record) {
|
2009-01-21 00:13:31 +03:00
|
|
|
this._log.trace(" -> processing history entry: " + record.cleartext.uri);
|
|
|
|
|
2009-01-03 12:04:17 +03:00
|
|
|
let uri = Utils.makeURI(record.cleartext.uri);
|
2009-01-21 00:13:31 +03:00
|
|
|
let curvisits = [];
|
|
|
|
if (this.urlExists(uri))
|
|
|
|
curvisits = this._getVisits(record.cleartext.uri);
|
|
|
|
|
2009-01-03 12:04:17 +03:00
|
|
|
let visit;
|
|
|
|
while ((visit = record.cleartext.visits.pop())) {
|
2009-01-21 00:13:31 +03:00
|
|
|
if (curvisits.filter(function(i) i.date == visit.date).length)
|
|
|
|
continue;
|
2009-01-03 12:04:17 +03:00
|
|
|
this._log.debug(" visit " + visit.date);
|
|
|
|
this._hsvc.addVisit(uri, visit.date, null, visit.type,
|
|
|
|
(visit.type == 5 || visit.type == 6), 0);
|
|
|
|
}
|
|
|
|
this._hsvc.setPageTitle(uri, record.cleartext.title);
|
2009-01-21 00:13:31 +03:00
|
|
|
|
2009-01-28 04:08:47 +03:00
|
|
|
// Equalize IDs
|
2009-01-21 00:13:31 +03:00
|
|
|
let localId = this._getGUID(record.cleartext.uri);
|
|
|
|
if (localId != record.id)
|
|
|
|
this.changeItemID(localId, record.id);
|
|
|
|
|
2008-12-18 03:04:03 +03:00
|
|
|
},
|
|
|
|
|
2009-01-03 12:04:17 +03:00
|
|
|
itemExists: function HistStore_itemExists(id) {
|
|
|
|
if (this._findURLByGUID(id))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
},
|
2008-12-10 11:57:27 +03:00
|
|
|
|
2009-01-21 00:13:31 +03:00
|
|
|
urlExists: function HistStore_urlExists(url) {
|
|
|
|
if (typeof(url) == "string")
|
|
|
|
url = Utils.makeURI(url);
|
|
|
|
return this._hsvc.isVisited(url);
|
|
|
|
},
|
|
|
|
|
2009-02-19 11:36:55 +03:00
|
|
|
createRecord: function HistStore_createRecord(guid, cryptoMetaURL) {
|
2009-01-03 12:04:17 +03:00
|
|
|
let foo = this._findURLByGUID(guid);
|
|
|
|
let record = new HistoryRec();
|
2009-01-28 04:08:47 +03:00
|
|
|
record.id = guid;
|
2009-01-03 12:04:17 +03:00
|
|
|
if (foo) {
|
|
|
|
record.histUri = foo.url;
|
|
|
|
record.title = foo.title;
|
|
|
|
record.visits = this._getVisits(record.histUri);
|
2009-02-19 11:36:55 +03:00
|
|
|
record.encryption = cryptoMetaURL;
|
2008-06-04 00:56:16 +04:00
|
|
|
}
|
2009-04-03 21:38:47 +04:00
|
|
|
else
|
|
|
|
record.deleted = true;
|
2009-01-03 12:04:17 +03:00
|
|
|
this.cache.put(guid, record);
|
|
|
|
return record;
|
2008-06-04 00:56:16 +04:00
|
|
|
},
|
|
|
|
|
2008-12-10 11:57:27 +03:00
|
|
|
wipe: function HistStore_wipe() {
|
|
|
|
this._hsvc.removeAllPages();
|
2008-06-04 00:56:16 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function HistoryTracker() {
|
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
HistoryTracker.prototype = {
|
2008-12-09 23:26:14 +03:00
|
|
|
__proto__: Tracker.prototype,
|
2008-06-04 00:56:16 +04:00
|
|
|
_logName: "HistoryTracker",
|
2009-04-01 05:07:43 +04:00
|
|
|
file: "history",
|
2008-06-04 00:56:16 +04:00
|
|
|
|
2008-12-17 13:32:00 +03:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsINavHistoryObserver]),
|
|
|
|
|
2008-12-09 23:26:14 +03:00
|
|
|
get _hsvc() {
|
|
|
|
let hsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
|
|
|
|
getService(Ci.nsINavHistoryService);
|
|
|
|
this.__defineGetter__("_hsvc", function() hsvc);
|
|
|
|
return hsvc;
|
|
|
|
},
|
|
|
|
|
2008-12-13 00:55:58 +03:00
|
|
|
// FIXME: hack!
|
|
|
|
get _store() {
|
|
|
|
let store = new HistoryStore();
|
|
|
|
this.__defineGetter__("_store", function() store);
|
|
|
|
return store;
|
|
|
|
},
|
|
|
|
|
2008-12-09 23:26:14 +03:00
|
|
|
_init: function HT__init() {
|
2009-04-11 04:30:05 +04:00
|
|
|
Tracker.prototype._init.call(this);
|
2008-12-09 23:26:14 +03:00
|
|
|
this._hsvc.addObserver(this, false);
|
|
|
|
},
|
|
|
|
|
2008-12-13 00:55:58 +03:00
|
|
|
onBeginUpdateBatch: function HT_onBeginUpdateBatch() {},
|
|
|
|
onEndUpdateBatch: function HT_onEndUpdateBatch() {},
|
|
|
|
onPageChanged: function HT_onPageChanged() {},
|
|
|
|
onTitleChanged: function HT_onTitleChanged() {},
|
2008-06-04 00:56:16 +04:00
|
|
|
|
|
|
|
/* Every add or remove is worth 1 point.
|
2008-12-13 00:55:58 +03:00
|
|
|
* Clearing the whole history is worth 50 points (see below)
|
2008-06-04 00:56:16 +04:00
|
|
|
*/
|
2008-12-13 00:55:58 +03:00
|
|
|
_upScore: function BMT__upScore() {
|
2008-06-04 00:56:16 +04:00
|
|
|
this._score += 1;
|
|
|
|
},
|
2008-12-13 00:55:58 +03:00
|
|
|
|
|
|
|
onVisit: function HT_onVisit(uri, vid, time, session, referrer, trans) {
|
2009-02-02 22:43:06 +03:00
|
|
|
if (this.ignoreAll)
|
|
|
|
return;
|
2008-12-17 13:32:00 +03:00
|
|
|
this._log.trace("onVisit: " + uri.spec);
|
2009-01-14 02:55:35 +03:00
|
|
|
if (this.addChangedID(this._store._getGUID(uri)))
|
|
|
|
this._upScore();
|
2008-12-13 00:55:58 +03:00
|
|
|
},
|
2008-06-04 00:56:16 +04:00
|
|
|
onPageExpired: function HT_onPageExpired(uri, time, entry) {
|
|
|
|
},
|
|
|
|
onDeleteURI: function HT_onDeleteURI(uri) {
|
|
|
|
},
|
|
|
|
onClearHistory: function HT_onClearHistory() {
|
2008-12-13 00:55:58 +03:00
|
|
|
this._log.trace("onClearHistory");
|
2008-06-04 00:56:16 +04:00
|
|
|
this._score += 50;
|
|
|
|
}
|
2008-12-09 23:26:14 +03:00
|
|
|
};
|