2007-12-10 21:38:53 -08: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.
|
|
|
|
*
|
|
|
|
* The Original Code is Bookmarks Sync.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Mozilla.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2007
|
|
|
|
* 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 ***** */
|
|
|
|
|
2007-12-14 18:07:25 -08:00
|
|
|
const EXPORTED_SYMBOLS = ['Store', 'SnapshotStore', 'BookmarksStore',
|
2008-04-01 17:32:14 -07:00
|
|
|
'HistoryStore', 'CookieStore'];
|
2007-12-10 21:38:53 -08:00
|
|
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cr = Components.results;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
|
2007-12-14 18:07:25 -08:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2007-12-10 21:38:53 -08:00
|
|
|
Cu.import("resource://weave/log4moz.js");
|
|
|
|
Cu.import("resource://weave/constants.js");
|
|
|
|
Cu.import("resource://weave/util.js");
|
2008-03-26 23:51:01 -07:00
|
|
|
Cu.import("resource://weave/async.js");
|
|
|
|
|
|
|
|
Function.prototype.async = Async.sugar;
|
2007-12-10 21:38:53 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Data Stores
|
|
|
|
* These can wrap, serialize items and apply commands
|
|
|
|
*/
|
|
|
|
|
|
|
|
function Store() {
|
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
Store.prototype = {
|
|
|
|
_logName: "Store",
|
2008-03-26 23:11:15 -07:00
|
|
|
_yieldDuringApply: true,
|
2007-12-10 21:38:53 -08:00
|
|
|
|
2008-03-05 00:00:56 -08:00
|
|
|
__json: null,
|
|
|
|
get _json() {
|
|
|
|
if (!this.__json)
|
|
|
|
this.__json = Cc["@mozilla.org/dom/json;1"].
|
|
|
|
createInstance(Ci.nsIJSON);
|
|
|
|
return this.__json;
|
|
|
|
},
|
|
|
|
|
2007-12-10 21:38:53 -08:00
|
|
|
_init: function Store__init() {
|
|
|
|
this._log = Log4Moz.Service.getLogger("Service." + this._logName);
|
|
|
|
},
|
|
|
|
|
|
|
|
applyCommands: function Store_applyCommands(commandList) {
|
2008-04-01 16:36:08 -07:00
|
|
|
let self = yield;
|
|
|
|
let timer, listener;
|
2008-03-26 23:11:15 -07:00
|
|
|
|
2008-03-26 23:51:01 -07:00
|
|
|
if (this._yieldDuringApply) {
|
|
|
|
listener = new Utils.EventListener(self.cb);
|
2008-03-26 23:12:58 -07:00
|
|
|
timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
2008-03-26 23:51:01 -07:00
|
|
|
}
|
2008-03-26 23:11:15 -07:00
|
|
|
|
2007-12-14 18:07:25 -08:00
|
|
|
for (var i = 0; i < commandList.length; i++) {
|
2008-03-26 23:11:15 -07:00
|
|
|
if (this._yieldDuringApply) {
|
|
|
|
timer.initWithCallback(listener, 0, timer.TYPE_ONE_SHOT);
|
|
|
|
yield; // Yield to main loop
|
|
|
|
}
|
2007-12-14 18:07:25 -08:00
|
|
|
var command = commandList[i];
|
2008-03-05 00:00:56 -08:00
|
|
|
this._log.debug("Processing command: " + this._json.encode(command));
|
2007-12-14 18:07:25 -08:00
|
|
|
switch (command["action"]) {
|
|
|
|
case "create":
|
|
|
|
this._createCommand(command);
|
|
|
|
break;
|
|
|
|
case "remove":
|
|
|
|
this._removeCommand(command);
|
|
|
|
break;
|
|
|
|
case "edit":
|
|
|
|
this._editCommand(command);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
this._log.error("unknown action in command: " + command["action"]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-03-26 23:11:15 -07:00
|
|
|
self.done();
|
2007-12-14 18:07:25 -08:00
|
|
|
},
|
|
|
|
|
2007-12-19 13:24:31 -08:00
|
|
|
// override these in derived objects
|
|
|
|
wrap: function Store_wrap() {},
|
|
|
|
wipe: function Store_wipe() {},
|
|
|
|
resetGUIDs: function Store_resetGUIDs() {}
|
2007-12-10 21:38:53 -08:00
|
|
|
};
|
|
|
|
|
2007-12-14 18:07:25 -08:00
|
|
|
function SnapshotStore(name) {
|
|
|
|
this._init(name);
|
2007-12-10 21:38:53 -08:00
|
|
|
}
|
|
|
|
SnapshotStore.prototype = {
|
2007-12-19 13:24:31 -08:00
|
|
|
_logName: "SnapStore",
|
2007-12-10 21:38:53 -08:00
|
|
|
|
2007-12-14 18:07:25 -08:00
|
|
|
_filename: null,
|
|
|
|
get filename() {
|
|
|
|
if (this._filename === null)
|
|
|
|
throw "filename is null";
|
|
|
|
return this._filename;
|
|
|
|
},
|
|
|
|
set filename(value) {
|
|
|
|
this._filename = value + ".json";
|
|
|
|
},
|
|
|
|
|
2007-12-10 21:38:53 -08:00
|
|
|
__dirSvc: null,
|
|
|
|
get _dirSvc() {
|
|
|
|
if (!this.__dirSvc)
|
|
|
|
this.__dirSvc = Cc["@mozilla.org/file/directory_service;1"].
|
|
|
|
getService(Ci.nsIProperties);
|
|
|
|
return this.__dirSvc;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Last synced tree, version, and GUID (to detect if the store has
|
|
|
|
// been completely replaced and invalidate the snapshot)
|
|
|
|
|
|
|
|
_data: {},
|
|
|
|
get data() { return this._data; },
|
|
|
|
set data(value) { this._data = value; },
|
|
|
|
|
|
|
|
_version: 0,
|
|
|
|
get version() { return this._version; },
|
|
|
|
set version(value) { this._version = value; },
|
|
|
|
|
|
|
|
_GUID: null,
|
|
|
|
get GUID() {
|
|
|
|
if (!this._GUID) {
|
|
|
|
let uuidgen = Cc["@mozilla.org/uuid-generator;1"].
|
|
|
|
getService(Ci.nsIUUIDGenerator);
|
|
|
|
this._GUID = uuidgen.generateUUID().toString().replace(/[{}]/g, '');
|
|
|
|
}
|
|
|
|
return this._GUID;
|
|
|
|
},
|
|
|
|
set GUID(GUID) {
|
|
|
|
this._GUID = GUID;
|
|
|
|
},
|
|
|
|
|
2007-12-14 18:07:25 -08:00
|
|
|
_init: function SStore__init(name) {
|
|
|
|
this.filename = name;
|
|
|
|
this._log = Log4Moz.Service.getLogger("Service." + this._logName);
|
|
|
|
},
|
|
|
|
|
2007-12-19 13:24:31 -08:00
|
|
|
_createCommand: function SStore__createCommand(command) {
|
2008-03-05 00:00:56 -08:00
|
|
|
this._data[command.GUID] = Utils.deepCopy(command.data);
|
2007-12-19 13:24:31 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
_removeCommand: function SStore__removeCommand(command) {
|
|
|
|
delete this._data[command.GUID];
|
|
|
|
},
|
|
|
|
|
|
|
|
_editCommand: function SStore__editCommand(command) {
|
|
|
|
if ("GUID" in command.data) {
|
|
|
|
// special-case guid changes
|
|
|
|
let newGUID = command.data.GUID,
|
|
|
|
oldGUID = command.GUID;
|
|
|
|
|
|
|
|
this._data[newGUID] = this._data[oldGUID];
|
|
|
|
delete this._data[oldGUID]
|
|
|
|
|
|
|
|
for (let GUID in this._data) {
|
|
|
|
if (this._data[GUID].parentGUID == oldGUID)
|
|
|
|
this._data[GUID].parentGUID = newGUID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (let prop in command.data) {
|
|
|
|
if (prop == "GUID")
|
|
|
|
continue;
|
|
|
|
this._data[command.GUID][prop] = command.data[prop];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2007-12-10 21:38:53 -08:00
|
|
|
save: function SStore_save() {
|
|
|
|
this._log.info("Saving snapshot to disk");
|
|
|
|
|
|
|
|
let file = this._dirSvc.get("ProfD", Ci.nsIFile);
|
|
|
|
file.QueryInterface(Ci.nsILocalFile);
|
2007-12-19 19:49:28 -08:00
|
|
|
|
|
|
|
file.append("weave");
|
|
|
|
file.append("snapshots");
|
|
|
|
file.append(this.filename);
|
2007-12-10 21:38:53 -08:00
|
|
|
if (!file.exists())
|
|
|
|
file.create(file.NORMAL_FILE_TYPE, PERMS_FILE);
|
|
|
|
|
|
|
|
let out = {version: this.version,
|
|
|
|
GUID: this.GUID,
|
|
|
|
snapshot: this.data};
|
2008-03-05 00:00:56 -08:00
|
|
|
out = this._json.encode(out);
|
|
|
|
|
|
|
|
let [fos] = Utils.open(file, ">");
|
|
|
|
fos.writeString(out);
|
2007-12-10 21:38:53 -08:00
|
|
|
fos.close();
|
|
|
|
},
|
|
|
|
|
|
|
|
load: function SStore_load() {
|
|
|
|
let file = this._dirSvc.get("ProfD", Ci.nsIFile);
|
2007-12-21 16:07:42 -08:00
|
|
|
file.append("weave");
|
|
|
|
file.append("snapshots");
|
2007-12-14 18:07:25 -08:00
|
|
|
file.append(this.filename);
|
2007-12-10 21:38:53 -08:00
|
|
|
|
|
|
|
if (!file.exists())
|
|
|
|
return;
|
|
|
|
|
2008-03-05 17:11:08 -08:00
|
|
|
try {
|
|
|
|
let [is] = Utils.open(file, "<");
|
|
|
|
let json = Utils.readStream(is);
|
|
|
|
is.close();
|
|
|
|
json = this._json.decode(json);
|
|
|
|
|
|
|
|
if (json && 'snapshot' in json && 'version' in json && 'GUID' in json) {
|
|
|
|
this._log.info("Read saved snapshot from disk");
|
|
|
|
this.data = json.snapshot;
|
|
|
|
this.version = json.version;
|
|
|
|
this.GUID = json.GUID;
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
this._log.warn("Could not parse saved snapshot; reverting to initial-sync state");
|
|
|
|
this._log.debug("Exception: " + e);
|
2007-12-10 21:38:53 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
serialize: function SStore_serialize() {
|
2008-03-05 00:00:56 -08:00
|
|
|
let json = this._json.encode(this.data);
|
2007-12-10 21:38:53 -08:00
|
|
|
json = json.replace(/:{type/g, ":\n\t{type");
|
|
|
|
json = json.replace(/}, /g, "},\n ");
|
|
|
|
json = json.replace(/, parentGUID/g, ",\n\t parentGUID");
|
|
|
|
json = json.replace(/, index/g, ",\n\t index");
|
|
|
|
json = json.replace(/, title/g, ",\n\t title");
|
|
|
|
json = json.replace(/, URI/g, ",\n\t URI");
|
|
|
|
json = json.replace(/, tags/g, ",\n\t tags");
|
|
|
|
json = json.replace(/, keyword/g, ",\n\t keyword");
|
|
|
|
return json;
|
|
|
|
},
|
|
|
|
|
|
|
|
wrap: function SStore_wrap() {
|
2007-12-19 13:24:31 -08:00
|
|
|
return this.data;
|
2007-12-10 21:38:53 -08:00
|
|
|
},
|
|
|
|
|
2007-12-19 13:24:31 -08:00
|
|
|
wipe: function SStore_wipe() {
|
|
|
|
this.data = {};
|
|
|
|
this.version = -1;
|
|
|
|
this.GUID = null;
|
|
|
|
this.save();
|
2007-12-10 21:38:53 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
SnapshotStore.prototype.__proto__ = new Store();
|
|
|
|
|
|
|
|
function BookmarksStore() {
|
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
BookmarksStore.prototype = {
|
|
|
|
_logName: "BStore",
|
|
|
|
|
|
|
|
__bms: null,
|
|
|
|
get _bms() {
|
|
|
|
if (!this.__bms)
|
|
|
|
this.__bms = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
|
|
|
getService(Ci.nsINavBookmarksService);
|
|
|
|
return this.__bms;
|
|
|
|
},
|
|
|
|
|
|
|
|
__hsvc: null,
|
|
|
|
get _hsvc() {
|
|
|
|
if (!this.__hsvc)
|
|
|
|
this.__hsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
|
|
|
|
getService(Ci.nsINavHistoryService);
|
|
|
|
return this.__hsvc;
|
|
|
|
},
|
|
|
|
|
|
|
|
__ls: null,
|
|
|
|
get _ls() {
|
|
|
|
if (!this.__ls)
|
|
|
|
this.__ls = Cc["@mozilla.org/browser/livemark-service;2"].
|
|
|
|
getService(Ci.nsILivemarkService);
|
|
|
|
return this.__ls;
|
|
|
|
},
|
|
|
|
|
|
|
|
__ms: null,
|
|
|
|
get _ms() {
|
|
|
|
if (!this.__ms)
|
|
|
|
this.__ms = Cc["@mozilla.org/microsummary/service;1"].
|
|
|
|
getService(Ci.nsIMicrosummaryService);
|
|
|
|
return this.__ms;
|
|
|
|
},
|
|
|
|
|
|
|
|
__ts: null,
|
|
|
|
get _ts() {
|
|
|
|
if (!this.__ts)
|
|
|
|
this.__ts = Cc["@mozilla.org/browser/tagging-service;1"].
|
|
|
|
getService(Ci.nsITaggingService);
|
|
|
|
return this.__ts;
|
|
|
|
},
|
|
|
|
|
|
|
|
__ans: null,
|
|
|
|
get _ans() {
|
|
|
|
if (!this.__ans)
|
|
|
|
this.__ans = Cc["@mozilla.org/browser/annotation-service;1"].
|
|
|
|
getService(Ci.nsIAnnotationService);
|
|
|
|
return this.__ans;
|
|
|
|
},
|
|
|
|
|
2008-03-21 15:56:41 -07:00
|
|
|
_getItemIdForGUID: function BStore__getItemIdForGUID(GUID) {
|
|
|
|
switch (GUID) {
|
|
|
|
case "menu":
|
|
|
|
return this._bms.bookmarksMenuFolder;
|
|
|
|
case "toolbar":
|
|
|
|
return this._bms.toolbarFolder;
|
|
|
|
case "unfiled":
|
|
|
|
return this._bms.unfiledBookmarksFolder;
|
|
|
|
default:
|
|
|
|
return this._bms.getItemIdForGUID(GUID);
|
2007-12-10 21:38:53 -08:00
|
|
|
}
|
2008-03-21 15:56:41 -07:00
|
|
|
return null;
|
2007-12-10 21:38:53 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
_createCommand: function BStore__createCommand(command) {
|
|
|
|
let newId;
|
2008-03-21 15:56:41 -07:00
|
|
|
let parentId = this._getItemIdForGUID(command.data.parentGUID);
|
2007-12-10 21:38:53 -08:00
|
|
|
|
|
|
|
if (parentId < 0) {
|
|
|
|
this._log.warn("Creating node with unknown parent -> reparenting to root");
|
|
|
|
parentId = this._bms.bookmarksMenuFolder;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (command.data.type) {
|
|
|
|
case "query":
|
|
|
|
case "bookmark":
|
2008-01-07 16:28:57 -08:00
|
|
|
case "microsummary": {
|
2008-03-25 23:01:34 -07:00
|
|
|
this._log.debug(" -> creating bookmark \"" + command.data.title + "\"");
|
2008-02-13 14:30:44 -08:00
|
|
|
let URI = Utils.makeURI(command.data.URI);
|
2007-12-10 21:38:53 -08:00
|
|
|
newId = this._bms.insertBookmark(parentId,
|
|
|
|
URI,
|
|
|
|
command.data.index,
|
|
|
|
command.data.title);
|
|
|
|
this._ts.untagURI(URI, null);
|
|
|
|
this._ts.tagURI(URI, command.data.tags);
|
|
|
|
this._bms.setKeywordForBookmark(newId, command.data.keyword);
|
|
|
|
|
|
|
|
if (command.data.type == "microsummary") {
|
2008-03-25 23:01:34 -07:00
|
|
|
this._log.debug(" \-> is a microsummary");
|
2008-02-13 14:30:44 -08:00
|
|
|
let genURI = Utils.makeURI(command.data.generatorURI);
|
2007-12-10 21:38:53 -08:00
|
|
|
try {
|
|
|
|
let micsum = this._ms.createMicrosummary(URI, genURI);
|
|
|
|
this._ms.setMicrosummary(newId, micsum);
|
|
|
|
}
|
|
|
|
catch(ex) { /* ignore "missing local generator" exceptions */ }
|
|
|
|
}
|
2008-01-07 16:28:57 -08:00
|
|
|
} break;
|
2007-12-10 21:38:53 -08:00
|
|
|
case "folder":
|
2008-03-25 23:01:34 -07:00
|
|
|
this._log.debug(" -> creating folder \"" + command.data.title + "\"");
|
2007-12-10 21:38:53 -08:00
|
|
|
newId = this._bms.createFolder(parentId,
|
|
|
|
command.data.title,
|
|
|
|
command.data.index);
|
|
|
|
break;
|
|
|
|
case "livemark":
|
2008-03-25 23:01:34 -07:00
|
|
|
this._log.debug(" -> creating livemark \"" + command.data.title + "\"");
|
2007-12-10 21:38:53 -08:00
|
|
|
newId = this._ls.createLivemark(parentId,
|
|
|
|
command.data.title,
|
2008-02-13 14:30:44 -08:00
|
|
|
Utils.makeURI(command.data.siteURI),
|
|
|
|
Utils.makeURI(command.data.feedURI),
|
2007-12-10 21:38:53 -08:00
|
|
|
command.data.index);
|
|
|
|
break;
|
2008-03-28 03:25:51 -07:00
|
|
|
case "mounted-share":
|
|
|
|
this._log.debug(" -> creating share mountpoint \"" + command.data.title + "\"");
|
|
|
|
newId = this._bms.createFolder(parentId,
|
|
|
|
command.data.title,
|
|
|
|
command.data.index);
|
2008-03-31 17:07:40 -07:00
|
|
|
|
2008-03-28 03:25:51 -07:00
|
|
|
this._ans.setItemAnnotation(newId, "weave/mounted-share-id",
|
|
|
|
command.data.mountId, 0, this._ans.EXPIRE_NEVER);
|
|
|
|
break;
|
2007-12-10 21:38:53 -08:00
|
|
|
case "separator":
|
2008-03-25 23:01:34 -07:00
|
|
|
this._log.debug(" -> creating separator");
|
2007-12-10 21:38:53 -08:00
|
|
|
newId = this._bms.insertSeparator(parentId, command.data.index);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
this._log.error("_createCommand: Unknown item type: " + command.data.type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (newId)
|
|
|
|
this._bms.setItemGUID(newId, command.GUID);
|
|
|
|
},
|
|
|
|
|
|
|
|
_removeCommand: function BStore__removeCommand(command) {
|
2008-03-21 15:56:41 -07:00
|
|
|
if (command.GUID == "menu" ||
|
|
|
|
command.GUID == "toolbar" ||
|
|
|
|
command.GUID == "unfiled") {
|
|
|
|
this._log.warn("Attempted to remove root node (" + command.GUID +
|
|
|
|
"). Skipping command.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-12-10 21:38:53 -08:00
|
|
|
var itemId = this._bms.getItemIdForGUID(command.GUID);
|
|
|
|
if (itemId < 0) {
|
|
|
|
this._log.warn("Attempted to remove item " + command.GUID +
|
|
|
|
", but it does not exist. Skipping.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var type = this._bms.getItemType(itemId);
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case this._bms.TYPE_BOOKMARK:
|
2008-03-25 23:01:34 -07:00
|
|
|
this._log.debug(" -> removing bookmark " + command.GUID);
|
2007-12-10 21:38:53 -08:00
|
|
|
this._bms.removeItem(itemId);
|
|
|
|
break;
|
|
|
|
case this._bms.TYPE_FOLDER:
|
2008-03-25 23:01:34 -07:00
|
|
|
this._log.debug(" -> removing folder " + command.GUID);
|
2007-12-10 21:38:53 -08:00
|
|
|
this._bms.removeFolder(itemId);
|
|
|
|
break;
|
|
|
|
case this._bms.TYPE_SEPARATOR:
|
2008-03-25 23:01:34 -07:00
|
|
|
this._log.debug(" -> removing separator " + command.GUID);
|
2007-12-10 21:38:53 -08:00
|
|
|
this._bms.removeItem(itemId);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
this._log.error("removeCommand: Unknown item type: " + type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_editCommand: function BStore__editCommand(command) {
|
2008-03-21 15:56:41 -07:00
|
|
|
if (command.GUID == "menu" ||
|
|
|
|
command.GUID == "toolbar" ||
|
|
|
|
command.GUID == "unfiled") {
|
|
|
|
this._log.warn("Attempted to edit root node (" + command.GUID +
|
|
|
|
"). Skipping command.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-12-10 21:38:53 -08:00
|
|
|
var itemId = this._bms.getItemIdForGUID(command.GUID);
|
|
|
|
if (itemId < 0) {
|
|
|
|
this._log.warn("Item for GUID " + command.GUID + " not found. Skipping.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let key in command.data) {
|
|
|
|
switch (key) {
|
2008-03-28 22:55:23 -07:00
|
|
|
case "type":
|
|
|
|
// all commands have this to help in reconciliation, but it makes
|
|
|
|
// no sense to edit it
|
|
|
|
break;
|
2007-12-10 21:38:53 -08:00
|
|
|
case "GUID":
|
2008-03-21 15:56:41 -07:00
|
|
|
var existing = this._getItemIdForGUID(command.data.GUID);
|
2007-12-10 21:38:53 -08:00
|
|
|
if (existing < 0)
|
|
|
|
this._bms.setItemGUID(itemId, command.data.GUID);
|
|
|
|
else
|
|
|
|
this._log.warn("Can't change GUID " + command.GUID +
|
|
|
|
" to " + command.data.GUID + ": GUID already exists.");
|
|
|
|
break;
|
|
|
|
case "title":
|
|
|
|
this._bms.setItemTitle(itemId, command.data.title);
|
|
|
|
break;
|
|
|
|
case "URI":
|
2008-02-13 14:30:44 -08:00
|
|
|
this._bms.changeBookmarkURI(itemId, Utils.makeURI(command.data.URI));
|
2007-12-10 21:38:53 -08:00
|
|
|
break;
|
|
|
|
case "index":
|
|
|
|
this._bms.moveItem(itemId, this._bms.getFolderIdForItem(itemId),
|
|
|
|
command.data.index);
|
|
|
|
break;
|
2008-01-07 16:28:57 -08:00
|
|
|
case "parentGUID": {
|
2007-12-10 21:38:53 -08:00
|
|
|
let index = -1;
|
|
|
|
if (command.data.index && command.data.index >= 0)
|
|
|
|
index = command.data.index;
|
|
|
|
this._bms.moveItem(
|
2008-03-21 15:56:41 -07:00
|
|
|
itemId, this._getItemIdForGUID(command.data.parentGUID), index);
|
2008-01-07 16:28:57 -08:00
|
|
|
} break;
|
|
|
|
case "tags": {
|
2007-12-10 21:38:53 -08:00
|
|
|
let tagsURI = this._bms.getBookmarkURI(itemId);
|
2008-03-31 17:07:40 -07:00
|
|
|
this._ts.untagURI(tagsURI, null);
|
2007-12-10 21:38:53 -08:00
|
|
|
this._ts.tagURI(tagsURI, command.data.tags);
|
2008-01-07 16:28:57 -08:00
|
|
|
} break;
|
2007-12-10 21:38:53 -08:00
|
|
|
case "keyword":
|
|
|
|
this._bms.setKeywordForBookmark(itemId, command.data.keyword);
|
|
|
|
break;
|
2008-01-07 16:28:57 -08:00
|
|
|
case "generatorURI": {
|
2008-02-13 14:30:44 -08:00
|
|
|
let micsumURI = Utils.makeURI(this._bms.getBookmarkURI(itemId));
|
|
|
|
let genURI = Utils.makeURI(command.data.generatorURI);
|
2007-12-10 21:38:53 -08:00
|
|
|
let micsum = this._ms.createMicrosummary(micsumURI, genURI);
|
|
|
|
this._ms.setMicrosummary(itemId, micsum);
|
2008-01-07 16:28:57 -08:00
|
|
|
} break;
|
2007-12-10 21:38:53 -08:00
|
|
|
case "siteURI":
|
2008-02-13 14:30:44 -08:00
|
|
|
this._ls.setSiteURI(itemId, Utils.makeURI(command.data.siteURI));
|
2007-12-10 21:38:53 -08:00
|
|
|
break;
|
|
|
|
case "feedURI":
|
2008-02-13 14:30:44 -08:00
|
|
|
this._ls.setFeedURI(itemId, Utils.makeURI(command.data.feedURI));
|
2007-12-10 21:38:53 -08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
this._log.warn("Can't change item property: " + key);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-03-21 15:56:41 -07:00
|
|
|
_getNode: function BSS__getNode(folder) {
|
|
|
|
let query = this._hsvc.getNewQuery();
|
|
|
|
query.setFolders([folder], 1);
|
|
|
|
return this._hsvc.executeQuery(query, this._hsvc.getNewQueryOptions()).root;
|
|
|
|
},
|
|
|
|
|
2008-03-28 03:25:51 -07:00
|
|
|
__wrap: function BSS___wrap(node, items, parentGUID, index, guidOverride) {
|
2008-03-21 15:56:41 -07:00
|
|
|
let GUID, item;
|
|
|
|
|
|
|
|
// we override the guid for the root items, "menu", "toolbar", etc.
|
|
|
|
if (guidOverride) {
|
|
|
|
GUID = guidOverride;
|
|
|
|
item = {};
|
|
|
|
} else {
|
|
|
|
GUID = this._bms.getItemGUID(node.itemId);
|
|
|
|
item = {parentGUID: parentGUID, index: index};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node.type == node.RESULT_TYPE_FOLDER) {
|
|
|
|
if (this._ls.isLivemark(node.itemId)) {
|
|
|
|
item.type = "livemark";
|
|
|
|
let siteURI = this._ls.getSiteURI(node.itemId);
|
|
|
|
let feedURI = this._ls.getFeedURI(node.itemId);
|
|
|
|
item.siteURI = siteURI? siteURI.spec : "";
|
|
|
|
item.feedURI = feedURI? feedURI.spec : "";
|
2008-03-28 03:25:51 -07:00
|
|
|
|
|
|
|
} else if (this._ans.itemHasAnnotation(node.itemId,
|
|
|
|
"weave/mounted-share-id")) {
|
|
|
|
item.type = "mounted-share";
|
|
|
|
item.title = node.title;
|
|
|
|
item.mountId = this._ans.getItemAnnotation(node.itemId,
|
|
|
|
"weave/mounted-share-id");
|
|
|
|
|
2008-03-21 15:56:41 -07:00
|
|
|
} else {
|
|
|
|
item.type = "folder";
|
|
|
|
node.QueryInterface(Ci.nsINavHistoryQueryResultNode);
|
|
|
|
node.containerOpen = true;
|
|
|
|
for (var i = 0; i < node.childCount; i++) {
|
|
|
|
this.__wrap(node.getChild(i), items, GUID, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!guidOverride)
|
|
|
|
item.title = node.title; // no titles for root nodes
|
|
|
|
|
|
|
|
} else if (node.type == node.RESULT_TYPE_URI ||
|
|
|
|
node.type == node.RESULT_TYPE_QUERY) {
|
|
|
|
if (this._ms.hasMicrosummary(node.itemId)) {
|
|
|
|
item.type = "microsummary";
|
|
|
|
let micsum = this._ms.getMicrosummary(node.itemId);
|
|
|
|
item.generatorURI = micsum.generator.uri.spec; // breaks local generators
|
|
|
|
} else if (node.type == node.RESULT_TYPE_QUERY) {
|
|
|
|
item.type = "query";
|
|
|
|
item.title = node.title;
|
|
|
|
} else {
|
|
|
|
item.type = "bookmark";
|
|
|
|
item.title = node.title;
|
|
|
|
}
|
|
|
|
item.URI = node.uri;
|
|
|
|
item.tags = this._ts.getTagsForURI(Utils.makeURI(node.uri), {});
|
|
|
|
item.keyword = this._bms.getKeywordForBookmark(node.itemId);
|
2007-12-10 21:38:53 -08:00
|
|
|
|
2008-03-21 15:56:41 -07:00
|
|
|
} else if (node.type == node.RESULT_TYPE_SEPARATOR) {
|
|
|
|
item.type = "separator";
|
2007-12-10 21:38:53 -08:00
|
|
|
|
2008-03-21 15:56:41 -07:00
|
|
|
} else {
|
|
|
|
this._log.warn("Warning: unknown item type, cannot serialize: " + node.type);
|
|
|
|
return;
|
2007-12-10 21:38:53 -08:00
|
|
|
}
|
|
|
|
|
2008-03-21 15:56:41 -07:00
|
|
|
items[GUID] = item;
|
|
|
|
},
|
|
|
|
|
|
|
|
// helper
|
2008-03-28 03:25:51 -07:00
|
|
|
_wrap: function BStore__wrap(node, items, rootName) {
|
2008-03-21 15:56:41 -07:00
|
|
|
return this.__wrap(node, items, null, null, rootName);
|
|
|
|
},
|
|
|
|
|
2008-03-28 03:25:51 -07:00
|
|
|
_wrapMount: function BStore__wrapMount(node, id) {
|
|
|
|
if (node.type != node.RESULT_TYPE_FOLDER)
|
|
|
|
throw "Trying to wrap a non-folder mounted share";
|
|
|
|
|
|
|
|
let GUID = this._bms.getItemGUID(node.itemId);
|
|
|
|
let ret = {rootGUID: GUID, userid: id, snapshot: {}};
|
|
|
|
|
|
|
|
node.QueryInterface(Ci.nsINavHistoryQueryResultNode);
|
|
|
|
node.containerOpen = true;
|
|
|
|
for (var i = 0; i < node.childCount; i++) {
|
|
|
|
this.__wrap(node.getChild(i), ret.snapshot, GUID, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove any share mountpoints
|
|
|
|
for (let guid in ret.snapshot) {
|
|
|
|
if (ret.snapshot[guid].type == "mounted-share")
|
|
|
|
delete ret.snapshot[guid];
|
2007-12-10 21:38:53 -08:00
|
|
|
}
|
|
|
|
|
2008-03-28 03:25:51 -07:00
|
|
|
return ret;
|
2008-03-31 17:07:40 -07:00
|
|
|
},
|
2008-03-28 03:25:51 -07:00
|
|
|
|
2008-03-21 15:56:41 -07:00
|
|
|
_resetGUIDs: function BSS__resetGUIDs(node) {
|
|
|
|
if (this._ans.itemHasAnnotation(node.itemId, "placesInternal/GUID"))
|
|
|
|
this._ans.removeItemAnnotation(node.itemId, "placesInternal/GUID");
|
|
|
|
|
|
|
|
if (node.type == node.RESULT_TYPE_FOLDER &&
|
|
|
|
!this._ls.isLivemark(node.itemId)) {
|
|
|
|
node.QueryInterface(Ci.nsINavHistoryQueryResultNode);
|
|
|
|
node.containerOpen = true;
|
|
|
|
for (var i = 0; i < node.childCount; i++) {
|
|
|
|
this._resetGUIDs(node.getChild(i));
|
|
|
|
}
|
2007-12-10 21:38:53 -08:00
|
|
|
}
|
2008-03-21 15:56:41 -07:00
|
|
|
},
|
2007-12-10 21:38:53 -08:00
|
|
|
|
2008-03-28 03:25:51 -07:00
|
|
|
findMounts: function BStore_findMounts() {
|
|
|
|
let ret = [];
|
|
|
|
let a = this._ans.getItemsWithAnnotation("weave/mounted-share-id", {});
|
|
|
|
for (let i = 0; i < a.length; i++) {
|
|
|
|
let id = this._ans.getItemAnnotation(a[i], "weave/mounted-share-id");
|
|
|
|
ret.push(this._wrapMount(this._getNode(a[i]), id));
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
},
|
|
|
|
|
2008-03-21 15:56:41 -07:00
|
|
|
wrap: function BStore_wrap() {
|
|
|
|
var items = {};
|
|
|
|
this._wrap(this._getNode(this._bms.bookmarksMenuFolder), items, "menu");
|
|
|
|
this._wrap(this._getNode(this._bms.toolbarFolder), items, "toolbar");
|
|
|
|
this._wrap(this._getNode(this._bms.unfiledBookmarksFolder), items, "unfiled");
|
|
|
|
return items;
|
2007-12-10 21:38:53 -08:00
|
|
|
},
|
|
|
|
|
2007-12-19 13:24:31 -08:00
|
|
|
wipe: function BStore_wipe() {
|
|
|
|
this._bms.removeFolderChildren(this._bms.bookmarksMenuFolder);
|
|
|
|
this._bms.removeFolderChildren(this._bms.toolbarFolder);
|
|
|
|
this._bms.removeFolderChildren(this._bms.unfiledBookmarksFolder);
|
|
|
|
},
|
|
|
|
|
2007-12-10 21:38:53 -08:00
|
|
|
resetGUIDs: function BStore_resetGUIDs() {
|
2008-03-21 15:56:41 -07:00
|
|
|
this._resetGUIDs(this._getNode(this._bms.bookmarksMenuFolder));
|
|
|
|
this._resetGUIDs(this._getNode(this._bms.toolbarFolder));
|
|
|
|
this._resetGUIDs(this._getNode(this._bms.unfiledBookmarksFolder));
|
2007-12-10 21:38:53 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
BookmarksStore.prototype.__proto__ = new Store();
|
|
|
|
|
2007-12-14 18:07:25 -08:00
|
|
|
function HistoryStore() {
|
|
|
|
this._init();
|
2007-12-10 21:38:53 -08:00
|
|
|
}
|
2007-12-14 18:07:25 -08:00
|
|
|
HistoryStore.prototype = {
|
|
|
|
_logName: "HistStore",
|
|
|
|
|
|
|
|
__hsvc: null,
|
|
|
|
get _hsvc() {
|
2008-03-25 23:01:34 -07:00
|
|
|
if (!this.__hsvc) {
|
2007-12-14 18:07:25 -08:00
|
|
|
this.__hsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
|
|
|
|
getService(Ci.nsINavHistoryService);
|
2008-03-25 23:01:34 -07:00
|
|
|
this.__hsvc.QueryInterface(Ci.nsIGlobalHistory2);
|
|
|
|
this.__hsvc.QueryInterface(Ci.nsIBrowserHistory);
|
|
|
|
}
|
2007-12-14 18:07:25 -08:00
|
|
|
return this.__hsvc;
|
|
|
|
},
|
|
|
|
|
|
|
|
_createCommand: function HistStore__createCommand(command) {
|
2008-03-25 23:01:34 -07:00
|
|
|
this._log.debug(" -> creating history entry: " + command.GUID);
|
2007-12-19 13:24:31 -08:00
|
|
|
try {
|
2008-03-28 22:55:23 -07:00
|
|
|
let uri = Utils.makeURI(command.data.URI);
|
2008-03-25 23:01:34 -07:00
|
|
|
this._hsvc.addVisit(uri, command.data.time, null,
|
|
|
|
this._hsvc.TRANSITION_TYPED, false, null);
|
|
|
|
this._hsvc.setPageTitle(uri, command.data.title);
|
2007-12-19 13:24:31 -08:00
|
|
|
} catch (e) {
|
|
|
|
this._log.error("Exception caught: " + (e.message? e.message : e));
|
|
|
|
}
|
2007-12-14 18:07:25 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
_removeCommand: function HistStore__removeCommand(command) {
|
2008-03-28 22:55:23 -07:00
|
|
|
this._log.trace(" -> NOT removing history entry: " + command.GUID);
|
|
|
|
// we can't remove because we only sync the last 1000 items, not
|
2008-03-25 23:01:34 -07:00
|
|
|
// the whole store. So we don't know if remove commands were
|
|
|
|
// generated due to the user removing an entry or because it
|
2008-03-28 22:55:23 -07:00
|
|
|
// dropped past the 1000 item mark.
|
2007-12-14 18:07:25 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
_editCommand: function HistStore__editCommand(command) {
|
2008-03-28 22:55:23 -07:00
|
|
|
this._log.trace(" -> FIXME: NOT editing history entry: " + command.GUID);
|
2007-12-14 18:07:25 -08:00
|
|
|
// FIXME: implement!
|
|
|
|
},
|
|
|
|
|
2007-12-19 13:24:31 -08:00
|
|
|
_historyRoot: function HistStore__historyRoot() {
|
|
|
|
let query = this._hsvc.getNewQuery(),
|
|
|
|
options = this._hsvc.getNewQueryOptions();
|
|
|
|
|
2007-12-14 18:07:25 -08:00
|
|
|
query.minVisits = 1;
|
2008-03-28 22:55:23 -07:00
|
|
|
options.maxResults = 1000;
|
|
|
|
options.resultType = options.RESULTS_AS_VISIT; // FULL_VISIT does not work
|
|
|
|
options.sortingMode = options.SORT_BY_DATE_DESCENDING;
|
2007-12-19 13:24:31 -08:00
|
|
|
options.queryType = options.QUERY_TYPE_HISTORY;
|
|
|
|
|
|
|
|
let root = this._hsvc.executeQuery(query, options).root;
|
2007-12-14 18:07:25 -08:00
|
|
|
root.QueryInterface(Ci.nsINavHistoryQueryResultNode);
|
2007-12-19 13:24:31 -08:00
|
|
|
return root;
|
|
|
|
},
|
|
|
|
|
|
|
|
wrap: function HistStore_wrap() {
|
|
|
|
let root = this._historyRoot();
|
2007-12-14 18:07:25 -08:00
|
|
|
root.containerOpen = true;
|
|
|
|
let items = {};
|
|
|
|
for (let i = 0; i < root.childCount; i++) {
|
|
|
|
let item = root.getChild(i);
|
2008-03-28 22:55:23 -07:00
|
|
|
let guid = item.time + ":" + item.uri
|
|
|
|
items[guid] = {parentGUID: '',
|
2007-12-14 18:07:25 -08:00
|
|
|
title: item.title,
|
|
|
|
URI: item.uri,
|
2008-03-25 23:01:34 -07:00
|
|
|
time: item.time
|
2007-12-14 18:07:25 -08:00
|
|
|
};
|
2008-03-28 22:55:23 -07:00
|
|
|
// FIXME: sync transition type - requires FULL_VISITs
|
2007-12-14 18:07:25 -08:00
|
|
|
}
|
|
|
|
return items;
|
2007-12-19 13:24:31 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
wipe: function HistStore_wipe() {
|
2008-03-25 23:01:34 -07:00
|
|
|
this._hsvc.removeAllPages();
|
2007-12-14 18:07:25 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
HistoryStore.prototype.__proto__ = new Store();
|
2008-03-11 10:08:38 -07:00
|
|
|
|
|
|
|
|
|
|
|
function CookieStore() {
|
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
CookieStore.prototype = {
|
|
|
|
_logName: "CookieStore",
|
|
|
|
|
|
|
|
|
|
|
|
// Documentation of the nsICookie interface says:
|
|
|
|
// name ACString The name of the cookie. Read only.
|
|
|
|
// value ACString The cookie value. Read only.
|
|
|
|
// isDomain boolean True if the cookie is a domain cookie, false otherwise. Read only.
|
|
|
|
// host AUTF8String The host (possibly fully qualified) of the cookie. Read only.
|
|
|
|
// path AUTF8String The path pertaining to the cookie. Read only.
|
|
|
|
// isSecure boolean True if the cookie was transmitted over ssl, false otherwise. Read only.
|
|
|
|
// expires PRUint64 Expiration time (local timezone) expressed as number of seconds since Jan 1, 1970. Read only.
|
|
|
|
// status nsCookieStatus Holds the P3P status of cookie. Read only.
|
|
|
|
// policy nsCookiePolicy Holds the site's compact policy value. Read only.
|
|
|
|
// nsICookie2 deprecates expires, status, and policy, and adds:
|
|
|
|
//rawHost AUTF8String The host (possibly fully qualified) of the cookie without a leading dot to represent if it is a domain cookie. Read only.
|
|
|
|
//isSession boolean True if the cookie is a session cookie. Read only.
|
|
|
|
//expiry PRInt64 the actual expiry time of the cookie (where 0 does not represent a session cookie). Read only.
|
|
|
|
//isHttpOnly boolean True if the cookie is an http only cookie. Read only.
|
|
|
|
|
|
|
|
|
|
|
|
__cookieManager: null,
|
|
|
|
get _cookieManager() {
|
|
|
|
if (!this.__cookieManager)
|
|
|
|
this.__cookieManager = Cc["@mozilla.org/cookiemanager;1"].
|
|
|
|
getService(Ci.nsICookieManager2);
|
|
|
|
// need the 2nd revision of the ICookieManager interface
|
|
|
|
// because it supports add() and the 1st one doesn't.
|
|
|
|
return this.__cookieManager
|
|
|
|
},
|
|
|
|
|
|
|
|
_createCommand: function HistStore__createCommand(command) {
|
2008-04-04 12:08:04 -07:00
|
|
|
/* we got a command to create a cookie in the local browser
|
|
|
|
in order to sync with the server. */
|
2008-03-11 10:08:38 -07:00
|
|
|
|
2008-04-04 12:08:04 -07:00
|
|
|
this._log.info("CookieStore got createCommand: " + command );
|
|
|
|
// this assumes command.data fits the nsICookie2 interface
|
|
|
|
this._cookieManager.add( command.data.host,
|
|
|
|
command.data.path,
|
|
|
|
command.data.name,
|
|
|
|
command.data.value,
|
|
|
|
command.data.isSecure,
|
|
|
|
command.data.isHttpOnly,
|
|
|
|
command.data.isSession,
|
|
|
|
command.data.expiry );
|
2008-03-11 10:08:38 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_removeCommand: function CookieStore__removeCommand(command) {
|
2008-04-04 12:08:04 -07:00
|
|
|
/* we got a command to remove a cookie from the local browser
|
|
|
|
in order to sync with the server.
|
|
|
|
command.data appears to be equivalent to what wrap() puts in
|
|
|
|
the JSON dictionary. */
|
2008-03-11 10:08:38 -07:00
|
|
|
|
2008-04-04 12:08:04 -07:00
|
|
|
this._log.info("CookieStore got removeCommand: " + command );
|
2008-03-11 10:08:38 -07:00
|
|
|
|
2008-04-04 12:08:04 -07:00
|
|
|
/* I think it goes like this, according to
|
|
|
|
http://developer.mozilla.org/en/docs/nsICookieManager
|
|
|
|
the last argument is "always block cookies from this domain?"
|
|
|
|
and the answer is "no". */
|
|
|
|
this._cookieManager.remove( command.data.host,
|
|
|
|
command.data.name,
|
|
|
|
command.data.path,
|
|
|
|
false );
|
2008-03-11 10:08:38 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_editCommand: function CookieStore__editCommand(command) {
|
2008-04-04 12:08:04 -07:00
|
|
|
/* we got a command to change a cookie in the local browser
|
|
|
|
in order to sync with the server.
|
2008-03-11 10:08:38 -07:00
|
|
|
|
2008-04-04 12:08:04 -07:00
|
|
|
if the local copy of the cookie is more-recently modified, it
|
|
|
|
should be kept, but if it's older, it should be replaced with
|
|
|
|
the server's copy.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Problem: The nsICookie interface doesn't seem to include the date/time
|
|
|
|
that the cookie was set -- only the expiry. TODO: Figure out
|
|
|
|
the best way to deal with this. */
|
|
|
|
this._log.info("CookieStore got editCommand: " + command );
|
|
|
|
|
|
|
|
this._log.debug( "Info on command object passed in: " );
|
|
|
|
for ( var x in command )
|
|
|
|
{
|
|
|
|
this._log.debug( "Command." + x + " = " + command[x] );
|
|
|
|
}
|
|
|
|
for ( var y in command.data )
|
|
|
|
{
|
|
|
|
this._log.debug( "Command.data." + y + " = " + command.data[y] );
|
|
|
|
}
|
2008-04-03 14:26:06 -07:00
|
|
|
},
|
2008-03-11 10:08:38 -07:00
|
|
|
|
|
|
|
wrap: function CookieStore_wrap() {
|
2008-04-04 12:08:04 -07:00
|
|
|
/* Return contents of this store, as JSON.
|
|
|
|
A dictionary of cookies where the keys are GUIDs and the
|
|
|
|
values are sub-dictionaries containing all cookie fields. */
|
|
|
|
|
|
|
|
let items = {};
|
|
|
|
var iter = this._cookieManager.enumerator;
|
|
|
|
while (iter.hasMoreElements()){
|
|
|
|
var cookie = iter.getNext();
|
|
|
|
if (cookie instanceof Ci.nsICookie){
|
|
|
|
// String used to identify cookies is
|
|
|
|
// host:path:name
|
2008-04-04 12:09:04 -07:00
|
|
|
let key = cookie.host + ":" + cookie.path + ":" + cookie.name;
|
|
|
|
items[ key ] = { parentGUID: '',
|
|
|
|
name: cookie.name,
|
|
|
|
value: cookie.value,
|
|
|
|
isDomain: cookie.isDomain,
|
|
|
|
host: cookie.host,
|
|
|
|
path: cookie.path,
|
|
|
|
isSecure: cookie.isSecure,
|
|
|
|
// nsICookie2 values:
|
|
|
|
rawHost: cookie.rawHost,
|
|
|
|
isSession: cookie.isSession,
|
|
|
|
expiry: cookie.expiry,
|
|
|
|
isHttpOnly: cookie.isHttpOnly }
|
2008-04-04 12:08:04 -07:00
|
|
|
|
|
|
|
/* See http://developer.mozilla.org/en/docs/nsICookie
|
|
|
|
Note: not syncing "expires", "status", or "policy"
|
|
|
|
since they're deprecated. */
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2008-03-11 10:08:38 -07:00
|
|
|
return items;
|
|
|
|
},
|
|
|
|
|
|
|
|
wipe: function CookieStore_wipe() {
|
2008-04-04 12:08:04 -07:00
|
|
|
/* Remove everything from the store. Return nothing.
|
|
|
|
TODO are the semantics of this just wiping out an internal
|
|
|
|
buffer, or am I supposed to wipe out all cookies from
|
|
|
|
the browser itself for reals? */
|
|
|
|
this._cookieManager.removeAll()
|
2008-03-11 10:08:38 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
resetGUIDs: function CookieStore_resetGUIDs() {
|
2008-04-04 12:08:04 -07:00
|
|
|
/* called in the case where remote/local sync GUIDs do not
|
|
|
|
match. We do need to override this, but since we're deriving
|
|
|
|
GUIDs from the cookie data itself and not generating them,
|
|
|
|
there's basically no way they can get "out of sync" so there's
|
|
|
|
nothing to do here. */
|
2008-03-11 10:08:38 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
CookieStore.prototype.__proto__ = new Store();
|