зеркало из https://github.com/mozilla/gecko-dev.git
add sharing ui+backend code (not working yet); make engines less chatty when applying commands
This commit is contained in:
Родитель
89a59249b4
Коммит
4bbd3af126
|
@ -0,0 +1,3 @@
|
|||
<!ENTITY dialog.title "Weave Sharing">
|
||||
<!ENTITY dialog.label "Enter a Weave ID to share bookmarks with:">
|
||||
<!ENTITY username.label "Email:">
|
|
@ -2,5 +2,6 @@
|
|||
<!ENTITY logInItem.label "Sign In...">
|
||||
<!ENTITY logOutItem.label "Sign Out">
|
||||
<!ENTITY syncNowItem.label "Sync Now">
|
||||
<!ENTITY shareItem.label "Share Bookmarks...">
|
||||
<!ENTITY openPrefsItem.label "Weave Preferences...">
|
||||
<!ENTITY openLogItem.label "Activity Log...">
|
||||
|
|
|
@ -676,10 +676,63 @@ Engine.prototype = {
|
|||
self.done(ret)
|
||||
},
|
||||
|
||||
_share: function Engine__share(username) {
|
||||
let self = yield;
|
||||
|
||||
this._getSymKey.async(this, self.cb);
|
||||
yield;
|
||||
|
||||
let base = this._dav.baseURL;
|
||||
try {
|
||||
// copied from getSymKey
|
||||
this._dav.GET(this.keysFile, self.cb);
|
||||
let ret = yield;
|
||||
Utils.ensureStatus(ret.status,
|
||||
"Could not get keys file.", [[200,300]]);
|
||||
let keys = this._json.decode(keysResp.responseText);
|
||||
|
||||
// get the other user's pubkey
|
||||
let hash = Utils.sha1(username);
|
||||
this._dav.baseURL = serverURL + "user/" + hash + "/"; //FIXME: very ugly!
|
||||
|
||||
this._dav.GET("public/pubkey", self.cb);
|
||||
ret = yield;
|
||||
Utils.ensureStatus(ret.status,
|
||||
"Could not get public key for user" + username);
|
||||
let id = new Identity();
|
||||
id.pubkey = ret.responseText;
|
||||
|
||||
this._dav.baseURL = base;
|
||||
|
||||
// now encrypt the symkey with their pubkey and upload the new keyring
|
||||
Crypto.RSAencrypt.async(Crypto, self.cb, this._engineId.password, id);
|
||||
let enckey = yield;
|
||||
if (!enckey)
|
||||
throw "Could not encrypt symmetric encryption key";
|
||||
|
||||
keys.ring[hash] = enckey;
|
||||
this._dav.PUT(this.keysFile, this._json.encode(keys), self.cb);
|
||||
ret = yield;
|
||||
Utils.ensureStatus(ret.status, "Could not upload keyring file.");
|
||||
|
||||
} catch (e) {
|
||||
throw e;
|
||||
|
||||
} finally {
|
||||
this._dav.baseURL = base;
|
||||
}
|
||||
|
||||
self.done();
|
||||
},
|
||||
|
||||
sync: function Engine_sync(onComplete) {
|
||||
return this._sync.async(this, onComplete);
|
||||
},
|
||||
|
||||
share: function Engine_share(onComplete, username) {
|
||||
return this._share.async(this, onComplete, username);
|
||||
},
|
||||
|
||||
resetServer: function Engine_resetServer(onComplete) {
|
||||
return this._resetServer.async(this, onComplete);
|
||||
},
|
||||
|
|
|
@ -66,30 +66,7 @@ Identity.prototype = {
|
|||
get username() { return this._username; },
|
||||
set username(value) { this._username = value; },
|
||||
|
||||
get userHash() {
|
||||
//this._log.trace("Hashing username " + this.username);
|
||||
|
||||
let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].
|
||||
createInstance(Ci.nsIScriptableUnicodeConverter);
|
||||
converter.charset = "UTF-8";
|
||||
|
||||
let hasher = Cc["@mozilla.org/security/hash;1"]
|
||||
.createInstance(Ci.nsICryptoHash);
|
||||
hasher.init(hasher.SHA1);
|
||||
|
||||
let data = converter.convertToByteArray(this.username, {});
|
||||
hasher.update(data, data.length);
|
||||
let rawHash = hasher.finish(false);
|
||||
|
||||
// return the two-digit hexadecimal code for a byte
|
||||
function toHexString(charCode) {
|
||||
return ("0" + charCode.toString(16)).slice(-2);
|
||||
}
|
||||
|
||||
let hash = [toHexString(rawHash.charCodeAt(i)) for (i in rawHash)].join("");
|
||||
//this._log.trace("Username hashes to " + hash);
|
||||
return hash;
|
||||
},
|
||||
get userHash() { return Utils.sha1(this.username); },
|
||||
|
||||
_privkey: null,
|
||||
get privkey() { return this._privkey; },
|
||||
|
|
|
@ -565,7 +565,7 @@ WeaveSvc.prototype = {
|
|||
_resetServer: function WeaveSync__resetServer() {
|
||||
let self = yield;
|
||||
|
||||
this._lock.async(this, self.cb)
|
||||
this._lock.async(this, self.cb);
|
||||
let locked = yield;
|
||||
if (!locked)
|
||||
return;
|
||||
|
@ -606,6 +606,28 @@ WeaveSvc.prototype = {
|
|||
self.done();
|
||||
},
|
||||
|
||||
_shareBookmarks: function WeaveSync__shareBookmarks(username) {
|
||||
let self = yield;
|
||||
|
||||
try {
|
||||
//this._lock.async(this, self.cb);
|
||||
//let locked = yield;
|
||||
//if (!locked)
|
||||
// return;
|
||||
|
||||
this._bmkEngine.share(self.cb, username);
|
||||
|
||||
} catch (e) {
|
||||
throw e;
|
||||
|
||||
} finally {
|
||||
//this._unlock.async(this, self.cb);
|
||||
//yield;
|
||||
}
|
||||
|
||||
self.done();
|
||||
},
|
||||
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupports]),
|
||||
|
||||
// nsIObserver
|
||||
|
@ -642,5 +664,8 @@ WeaveSvc.prototype = {
|
|||
|
||||
sync: function WeaveSync_sync() { this._sync.async(this); },
|
||||
resetServer: function WeaveSync_resetServer() { this._resetServer.async(this); },
|
||||
resetClient: function WeaveSync_resetClient() { this._resetClient.async(this); }
|
||||
resetClient: function WeaveSync_resetClient() { this._resetClient.async(this); },
|
||||
shareBookmarks: function WeaveSync_shareBookmarks(username) {
|
||||
this._shareBookmarks.async(this, null, username);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -335,7 +335,7 @@ BookmarksStore.prototype = {
|
|||
case "query":
|
||||
case "bookmark":
|
||||
case "microsummary": {
|
||||
this._log.info(" -> creating bookmark \"" + command.data.title + "\"");
|
||||
this._log.debug(" -> creating bookmark \"" + command.data.title + "\"");
|
||||
let URI = Utils.makeURI(command.data.URI);
|
||||
newId = this._bms.insertBookmark(parentId,
|
||||
URI,
|
||||
|
@ -346,7 +346,7 @@ BookmarksStore.prototype = {
|
|||
this._bms.setKeywordForBookmark(newId, command.data.keyword);
|
||||
|
||||
if (command.data.type == "microsummary") {
|
||||
this._log.info(" \-> is a microsummary");
|
||||
this._log.debug(" \-> is a microsummary");
|
||||
let genURI = Utils.makeURI(command.data.generatorURI);
|
||||
try {
|
||||
let micsum = this._ms.createMicrosummary(URI, genURI);
|
||||
|
@ -356,13 +356,13 @@ BookmarksStore.prototype = {
|
|||
}
|
||||
} break;
|
||||
case "folder":
|
||||
this._log.info(" -> creating folder \"" + command.data.title + "\"");
|
||||
this._log.debug(" -> creating folder \"" + command.data.title + "\"");
|
||||
newId = this._bms.createFolder(parentId,
|
||||
command.data.title,
|
||||
command.data.index);
|
||||
break;
|
||||
case "livemark":
|
||||
this._log.info(" -> creating livemark \"" + command.data.title + "\"");
|
||||
this._log.debug(" -> creating livemark \"" + command.data.title + "\"");
|
||||
newId = this._ls.createLivemark(parentId,
|
||||
command.data.title,
|
||||
Utils.makeURI(command.data.siteURI),
|
||||
|
@ -370,7 +370,7 @@ BookmarksStore.prototype = {
|
|||
command.data.index);
|
||||
break;
|
||||
case "separator":
|
||||
this._log.info(" -> creating separator");
|
||||
this._log.debug(" -> creating separator");
|
||||
newId = this._bms.insertSeparator(parentId, command.data.index);
|
||||
break;
|
||||
default:
|
||||
|
@ -400,15 +400,15 @@ BookmarksStore.prototype = {
|
|||
|
||||
switch (type) {
|
||||
case this._bms.TYPE_BOOKMARK:
|
||||
this._log.info(" -> removing bookmark " + command.GUID);
|
||||
this._log.debug(" -> removing bookmark " + command.GUID);
|
||||
this._bms.removeItem(itemId);
|
||||
break;
|
||||
case this._bms.TYPE_FOLDER:
|
||||
this._log.info(" -> removing folder " + command.GUID);
|
||||
this._log.debug(" -> removing folder " + command.GUID);
|
||||
this._bms.removeFolder(itemId);
|
||||
break;
|
||||
case this._bms.TYPE_SEPARATOR:
|
||||
this._log.info(" -> removing separator " + command.GUID);
|
||||
this._log.debug(" -> removing separator " + command.GUID);
|
||||
this._bms.removeItem(itemId);
|
||||
break;
|
||||
default:
|
||||
|
@ -599,40 +599,37 @@ HistoryStore.prototype = {
|
|||
|
||||
__hsvc: null,
|
||||
get _hsvc() {
|
||||
if (!this.__hsvc)
|
||||
if (!this.__hsvc) {
|
||||
this.__hsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsINavHistoryService);
|
||||
this.__hsvc.QueryInterface(Ci.nsIGlobalHistory2);
|
||||
this.__hsvc.QueryInterface(Ci.nsIBrowserHistory);
|
||||
}
|
||||
return this.__hsvc;
|
||||
},
|
||||
|
||||
__browserHist: null,
|
||||
get _browserHist() {
|
||||
if (!this.__browserHist)
|
||||
this.__browserHist = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsIBrowserHistory);
|
||||
return this.__browserHist;
|
||||
},
|
||||
|
||||
_createCommand: function HistStore__createCommand(command) {
|
||||
this._log.info(" -> creating history entry: " + command.GUID);
|
||||
this._log.debug(" -> creating history entry: " + command.GUID);
|
||||
try {
|
||||
this._browserHist.addPageWithDetails(Utils.makeURI(command.GUID),
|
||||
command.data.title,
|
||||
command.data.time);
|
||||
this._hsvc.setPageDetails(Utils.makeURI(command.GUID), command.data.title,
|
||||
command.data.accessCount, false, false);
|
||||
let uri = Utils.makeURI(command.GUID);
|
||||
this._hsvc.addVisit(uri, command.data.time, null,
|
||||
this._hsvc.TRANSITION_TYPED, false, null);
|
||||
this._hsvc.setPageTitle(uri, command.data.title);
|
||||
} catch (e) {
|
||||
this._log.error("Exception caught: " + (e.message? e.message : e));
|
||||
}
|
||||
},
|
||||
|
||||
_removeCommand: function HistStore__removeCommand(command) {
|
||||
this._log.info(" -> NOT removing history entry: " + command.GUID);
|
||||
//this._browserHist.removePage(command.GUID);
|
||||
this._log.debug(" -> NOT removing history entry: " + command.GUID);
|
||||
// we can't remove because we only sync the last 500 items, not
|
||||
// the whole store. So we don't know if remove commands were
|
||||
// generated due to the user removing an entry or because it
|
||||
// dropped past the 500 item mark.
|
||||
},
|
||||
|
||||
_editCommand: function HistStore__editCommand(command) {
|
||||
this._log.info(" -> FIXME: NOT editing history entry: " + command.GUID);
|
||||
this._log.debug(" -> FIXME: NOT editing history entry: " + command.GUID);
|
||||
// FIXME: implement!
|
||||
},
|
||||
|
||||
|
@ -642,6 +639,7 @@ HistoryStore.prototype = {
|
|||
|
||||
query.minVisits = 1;
|
||||
options.maxResults = 500;
|
||||
options.resultType = options.RESULTS_AS_FULL_VISIT;
|
||||
options.sortingMode = query.SORT_BY_LASTMODIFIED_DESCENDING;
|
||||
options.queryType = options.QUERY_TYPE_HISTORY;
|
||||
|
||||
|
@ -659,16 +657,15 @@ HistoryStore.prototype = {
|
|||
items[item.uri] = {parentGUID: '',
|
||||
title: item.title,
|
||||
URI: item.uri,
|
||||
time: item.time,
|
||||
accessCount: item.accessCount,
|
||||
dateAdded: item.dateAdded,
|
||||
time: item.time
|
||||
};
|
||||
// FIXME: sync transition type
|
||||
}
|
||||
return items;
|
||||
},
|
||||
|
||||
wipe: function HistStore_wipe() {
|
||||
this._browserHist.removeAllPages();
|
||||
this._hsvc.removeAllPages();
|
||||
}
|
||||
};
|
||||
HistoryStore.prototype.__proto__ = new Store();
|
||||
|
|
|
@ -167,6 +167,28 @@ let Utils = {
|
|||
throw 'checkStatus failed';
|
||||
},
|
||||
|
||||
sha1: function Weave_sha1(string) {
|
||||
let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].
|
||||
createInstance(Ci.nsIScriptableUnicodeConverter);
|
||||
converter.charset = "UTF-8";
|
||||
|
||||
let hasher = Cc["@mozilla.org/security/hash;1"]
|
||||
.createInstance(Ci.nsICryptoHash);
|
||||
hasher.init(hasher.SHA1);
|
||||
|
||||
let data = converter.convertToByteArray(string, {});
|
||||
hasher.update(data, data.length);
|
||||
let rawHash = hasher.finish(false);
|
||||
|
||||
// return the two-digit hexadecimal code for a byte
|
||||
function toHexString(charCode) {
|
||||
return ("0" + charCode.toString(16)).slice(-2);
|
||||
}
|
||||
|
||||
let hash = [toHexString(rawHash.charCodeAt(i)) for (i in rawHash)].join("");
|
||||
return hash;
|
||||
},
|
||||
|
||||
makeURI: function Weave_makeURI(URIString) {
|
||||
if (URIString === null || URIString == "")
|
||||
return null;
|
||||
|
|
Загрузка…
Ссылка в новой задаче