initial commit of new about:weave

This commit is contained in:
Dan Mills 2009-08-18 20:03:11 -07:00
Родитель bea7925a6b
Коммит 27305124c1
5 изменённых файлов: 381 добавлений и 47 удалений

Просмотреть файл

@ -85,7 +85,7 @@ AboutWeaveService.prototype = {
newChannel: function(aURI) {
let ios = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService);
let ch = ios.newChannel("chrome://weave/content/weave.html", null, null);
let ch = ios.newChannel("chrome://weave/content/about/index.html", null, null);
ch.originalURI = aURI;
return ch;
}

Просмотреть файл

@ -0,0 +1,29 @@
welcome = Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam id neque lectus. Donec cursus pulvinar nibh at pretium. Vivamus ante tellus, accumsan vel placerat vestibulum, tristique ac augue. 'Cause that's how I roll.
#prev = « prev
#next = next »
prev = prev
next = next
signedin-title = Signed In
signedin-text = You are currently logged in as %S
signedin-signout = sign out
signin-title = Sign Into Weave
signin-newacct = new account
signin-username = username
signin-password = password
signin-passphrase = passphrase
signin-help = help
signin-help-url = https://services.mozilla.com/help/login/
newacct-title = New Weave Account
newacct-username = username
newacct-password = password
newacct-passphrase = passphrase
newacct-email = email address
newacct-tos-label = I agree to the
newacct-tos-label2 =
newacct-tos-link = Terms of Service
newacct-tos-url = http://labs.mozilla.com/projects/weave/tos/
recaptcha_response_field = Type in the words above

Просмотреть файл

@ -0,0 +1,238 @@
/* ***** 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 String Bundle.
*
* 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):
* Myk Melez <myk@mozilla.org>
*
* 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 ***** */
let EXPORTED_SYMBOLS = ["StringBundle"];
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cr = Components.results;
const Cu = Components.utils;
/**
* A string bundle.
*
* This object presents two APIs: a deprecated one that is equivalent to the API
* for the stringbundle XBL binding, to make it easy to switch from that binding
* to this module, and a new one that is simpler and easier to use.
*
* The benefit of this module over the XBL binding is that it can also be used
* in JavaScript modules and components, not only in chrome JS.
*
* To use this module, import it, create a new instance of StringBundle,
* and then use the instance's |get| and |getAll| methods to retrieve strings
* (you can get both plain and formatted strings with |get|):
*
* let strings =
* new StringBundle("chrome://example/locale/strings.properties");
* let foo = strings.get("foo");
* let barFormatted = strings.get("bar", [arg1, arg2]);
* for each (let string in strings.getAll())
* dump (string.key + " = " + string.value + "\n");
*
* @param url {String}
* the URL of the string bundle
*/
function StringBundle(url) {
this.url = url;
}
StringBundle.prototype = {
/**
* the locale associated with the application
* @type nsILocale
* @private
*/
get _appLocale() {
try {
return Cc["@mozilla.org/intl/nslocaleservice;1"].
getService(Ci.nsILocaleService).
getApplicationLocale();
}
catch(ex) {
return null;
}
},
/**
* the wrapped nsIStringBundle
* @type nsIStringBundle
* @private
*/
get _stringBundle() {
let stringBundle = Cc["@mozilla.org/intl/stringbundle;1"].
getService(Ci.nsIStringBundleService).
createBundle(this.url, this._appLocale);
this.__defineGetter__("_stringBundle", function() stringBundle);
return this._stringBundle;
},
// the new API
/**
* the URL of the string bundle
* @type String
*/
_url: null,
get url() {
return this._url;
},
set url(newVal) {
this._url = newVal;
delete this._stringBundle;
},
/**
* Get a string from the bundle.
*
* @param key {String}
* the identifier of the string to get
* @param args {array} [optional]
* an array of arguments that replace occurrences of %S in the string
*
* @returns {String} the value of the string
*/
get: function(key, args) {
if (args)
return this.stringBundle.formatStringFromName(key, args, args.length);
else
return this.stringBundle.GetStringFromName(key);
},
/**
* Get all the strings in the bundle.
*
* @returns {Array}
* an array of objects with key and value properties
*/
getAll: function() {
let strings = [];
// FIXME: for performance, return an enumerable array that wraps the string
// bundle's nsISimpleEnumerator (does JavaScript already support this?).
let enumerator = this.stringBundle.getSimpleEnumeration();
while (enumerator.hasMoreElements()) {
// We could simply return the nsIPropertyElement objects, but I think
// it's better to return standard JS objects that behave as consumers
// expect JS objects to behave (f.e. you can modify them dynamically).
let string = enumerator.getNext().QueryInterface(Ci.nsIPropertyElement);
strings.push({ key: string.key, value: string.value });
}
return strings;
},
// the deprecated XBL binding-compatible API
/**
* the URL of the string bundle
* @deprecated because its name doesn't make sense outside of an XBL binding
* @type String
*/
get src() {
return this.url;
},
set src(newVal) {
this.url = newVal;
},
/**
* the locale associated with the application
* @deprecated because it has never been used outside the XBL binding itself,
* and consumers should obtain it directly from the locale service anyway.
* @type nsILocale
*/
get appLocale() {
return this._appLocale;
},
/**
* the wrapped nsIStringBundle
* @deprecated because this module should provide all necessary functionality
* @type nsIStringBundle
*
* If you do ever need to use this, let the authors of this module know why
* so they can surface functionality for your use case in the module itself
* and you don't have to access this underlying XPCOM component.
*/
get stringBundle() {
return this._stringBundle;
},
/**
* Get a string from the bundle.
* @deprecated use |get| instead
*
* @param key {String}
* the identifier of the string to get
*
* @returns {String}
* the value of the string
*/
getString: function(key) {
return this.get(key);
},
/**
* Get a formatted string from the bundle.
* @deprecated use |get| instead
*
* @param key {string}
* the identifier of the string to get
* @param args {array}
* an array of arguments that replace occurrences of %S in the string
*
* @returns {String}
* the formatted value of the string
*/
getFormattedString: function(key, args) {
return this.get(key, args);
},
/**
* Get an enumeration of the strings in the bundle.
* @deprecated use |getAll| instead
*
* @returns {nsISimpleEnumerator}
* a enumeration of the strings in the bundle
*/
get strings() {
return this.stringBundle.getSimpleEnumeration();
}
}

Просмотреть файл

@ -399,8 +399,8 @@ WeaveSvc.prototype = {
break;
case FIREFOX_ID:
engines = ["Bookmarks", "Cookie", "Extension", "Form", "History",
"Input", "MicroFormat", "Password", "Plugin", "Prefs", "Tab",
engines = ["Bookmarks", "Cookie", "Extension", "Form", "History",
"Input", "MicroFormat", "Password", "Plugin", "Prefs", "Tab",
"Theme"];
break;
@ -532,7 +532,7 @@ WeaveSvc.prototype = {
this._log.debug("Verifying passphrase");
this.username = username;
ID.get("WeaveID").setTempPassword(password);
try {
let pubkey = PubKeys.getDefaultKey();
let privkey = PrivKeys.get(pubkey.privateKeyUri);
@ -551,7 +551,7 @@ WeaveSvc.prototype = {
this._catch(this._notify("changepph", "", function() {
let pubkey = PubKeys.getDefaultKey();
let privkey = PrivKeys.get(pubkey.privateKeyUri);
/* Re-encrypt with new passphrase.
* FIXME: verifyPassphrase first!
*/
@ -559,17 +559,17 @@ WeaveSvc.prototype = {
this.passphrase, privkey.payload.salt,
privkey.payload.iv, newphrase);
privkey.payload.keyData = newkey;
new Resource(privkey.uri).put(privkey.serialize());
this.passphrase = newphrase;
return true;
}))(),
changePassword: function WeaveSvc_changePassword(newpass)
this._catch(this._notify("changepwd", "", function() {
function enc(x) encodeURIComponent(x);
let message = "uid=" + enc(this.username) + "&password=" +
let message = "uid=" + enc(this.username) + "&password=" +
enc(this.password) + "&new=" + enc(newpass);
let url = Svc.Prefs.get('tmpServerURL') + '0.3/api/register/chpwd';
let res = new Weave.Resource(url);
@ -582,35 +582,35 @@ WeaveSvc.prototype = {
this._log.info("Password change failed: " + resp);
throw "Could not change password";
}
this.password = newpass;
return true;
}))(),
resetPassphrase: function WeaveSvc_resetPassphrase(newphrase)
this._catch(this._notify("resetpph", "", function() {
/* Make remote commands ready so we have a list of clients beforehand */
this.prepCommand("logout", []);
let clientsBackup = Clients._store.clients;
/* Wipe */
this.wipeServer();
/* Set remote commands before syncing */
Clients._store.clients = clientsBackup;
let username = this.username;
let password = this.password;
this.logout();
/* Set this so UI is updated on next run */
this.passphrase = newphrase;
/* Login in sync: this also generates new keys */
this.login(username, password, newphrase);
this.sync(true);
return true;
}))(),
login: function WeaveSvc_login(username, password, passphrase)
this._catch(this._lock(this._notify("login", "", function() {
this._loggedIn = false;
@ -659,37 +659,94 @@ WeaveSvc.prototype = {
Svc.Observer.notifyObservers(null, "weave:service:logout:finish", "");
},
_errorStr: function WeaveSvc__errorStr(code) {
switch (code) {
case "0":
return "uid-in-use";
case "-1":
return "invalid-http-method";
case "-2":
return "uid-missing";
case "-3":
return "uid-invalid";
case "-4":
return "mail-invalid";
case "-5":
return "mail-in-use";
case "-6":
return "captcha-challenge-missing";
case "-7":
return "captcha-response-missing";
case "-8":
return "password-missing";
case "-9":
return "internal-server-error";
case "-10":
return "server-quota-exceeded";
case "-11":
return "missing-new-field";
case "-12":
return "password-incorrect";
default:
return "generic-server-error";
}
},
checkUsername: function WeaveSvc_checkUsername(username) {
let url = Svc.Prefs.get('tmpServerURL') +
"0.3/api/register/checkuser/" + username;
let res = new Resource(url);
res.authenticator = new NoOpAuthenticator();
let data = res.get();
if (res.lastChannel.responseStatus == 200 && data == "0")
return "available";
return this._errorStr(data);
},
createAccount: function WeaveSvc_createAccount(username, password, email,
captchaChallenge, captchaResponse) {
let ret = null;
function enc(x) encodeURIComponent(x);
let message = "uid=" + enc(username) + "&password=" + enc(password) +
"&mail=" + enc(email) + "&recaptcha_challenge_field=" +
enc(captchaChallenge) + "&recaptcha_response_field=" + enc(captchaResponse);
let url = Svc.Prefs.get('tmpServerURL') + '0.3/api/register/new';
let res = new Weave.Resource(url);
let res = new Resource(url);
res.authenticator = new Weave.NoOpAuthenticator();
res.setHeader("Content-Type", "application/x-www-form-urlencoded",
"Content-Length", message.length);
// fixme: Resource throws on error - it really shouldn't :-/
let resp;
try {
resp = res.post(message);
}
catch(ex) {
this._log.trace("Create account error: " + ex);
}
ret = {
status: res.lastChannel.responseStatus,
response: resp
};
if (res.lastChannel.responseStatus != 200 &&
res.lastChannel.responseStatus != 201)
throw "Server returned error code " + res.lastChannel.responseStatus;
if (res.lastChannel.responseStatus != 200 &&
res.lastChannel.responseStatus != 201)
this._log.info("Failed to create account. " +
"status: " + res.lastChannel.responseStatus + ", " +
"response: " + resp);
else
this._log.info("Account created: " + resp);
ret.error = false;
return res.lastChannel.responseStatus;
} catch(ex) {
this._log.warn("Failed to create account: " + Utils.exceptionStr(ex));
ret.error = "generic-server-error";
if (ret.status == 400)
ret.error = this._errorStr(ret.status);
else if (ret.status == 417)
ret.error = "captcha-incorrect";
}
return ret;
},
// stuff we need to to after login, before we can really do
@ -703,7 +760,7 @@ WeaveSvc.prototype = {
let remoteVersion = (meta && meta.payload.storageVersion)?
meta.payload.storageVersion : "";
this._log.debug(["Weave Version:", WEAVE_VERSION, "Compatible:",
this._log.debug(["Weave Version:", WEAVE_VERSION, "Compatible:",
COMPATIBLE_VERSION, "Remote:", remoteVersion].join(" "));
if (!meta || !meta.payload.storageVersion || !meta.payload.syncID ||
@ -882,14 +939,14 @@ WeaveSvc.prototype = {
/**
* Call sync() on an idle timer
*
*
*/
syncOnIdle: function WeaveSvc_syncOnIdle() {
this._log.debug("Idle timer created for sync, will sync after " +
IDLE_TIME + " seconds of inactivity.");
Svc.Idle.addIdleObserver(this, IDLE_TIME);
},
/**
* Set a timer for the next sync
*/
@ -902,7 +959,7 @@ WeaveSvc.prototype = {
this._syncTimer.cancel();
else
this._syncTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
let listener = new Utils.EventListener(Utils.bind2(this,
function WeaveSvc__scheduleNextSyncCallback(timer) {
this._syncTimer = null;
@ -919,7 +976,7 @@ WeaveSvc.prototype = {
*/
_handleSyncError: function WeaveSvc__handleSyncError() {
let shouldBackoff = false;
let err = Weave.Service.detailedStatus.sync;
// we'll assume the server is just borked a little for these
switch (err) {
@ -931,16 +988,16 @@ WeaveSvc.prototype = {
// specifcally handle 500, 502, 503, 504 errors
// xxxmpc: what else should be in this list?
// this is sort of pseudocode, need a way to get at the
if (!shouldBackoff &&
// this is sort of pseudocode, need a way to get at the
if (!shouldBackoff &&
Utils.checkStatus(Records.lastResource.lastChannel.responseStatus, null, [500,[502,504]])) {
shouldBackoff = true;
}
// if this is a client error, do the next sync as normal and return
if (!shouldBackoff) {
this._scheduleNextSync();
return;
return;
}
// ok, something failed connecting to the server, rev the counter
@ -1279,7 +1336,7 @@ WeaveSvc.prototype = {
// Process each command in order
for each ({command: command, args: args} in commands) {
this._log.debug("Processing command: " + command + "(" + args + ")");
let engines = [args[0]];
switch (command) {
case "resetAll":

Просмотреть файл

@ -34,7 +34,7 @@
*
* ***** END LICENSE BLOCK ***** */
const EXPORTED_SYMBOLS = ['Utils', 'Svc'];
const EXPORTED_SYMBOLS = ['Utils', 'Svc', 'Str'];
const Cc = Components.classes;
const Ci = Components.interfaces;
@ -44,6 +44,7 @@ const Cu = Components.utils;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://weave/ext/Preferences.js");
Cu.import("resource://weave/ext/Observers.js");
Cu.import("resource://weave/ext/StringBundle.js");
Cu.import("resource://weave/constants.js");
Cu.import("resource://weave/log4moz.js");
@ -295,6 +296,11 @@ let Utils = {
dest.__defineGetter__(prop, getter);
},
lazyStrings: function Weave_lazyStrings(name) {
let bundle = "chrome://weave/locale/" + name + ".properties";
return function() new StringBundle(bundle);
},
deepEquals: function eq(a, b) {
// If they're triple equals, then it must be equals!
if (a === b)
@ -619,16 +625,16 @@ let Utils = {
win = win.activeWindow;
win["open" + type].apply(win, Array.slice(arguments, 2));
},
_openChromeWindow: function Utils_openCWindow(name, uri, options, args) {
Utils.openWindow(name, "chrome://weave/content/" + uri, options, args);
},
openWindow: function Utils_openWindow(name, uri, options, args) {
Utils._openWin(name, "Window", null, uri, "",
options || "centerscreen,chrome,dialog,resizable=yes", args);
options || "centerscreen,chrome,dialog,resizable=yes", args);
},
openDialog: function Utils_openDialog(name, uri, options, args) {
Utils._openWin(name, "Dialog", "chrome://weave/content/" + uri, "",
options || "centerscreen,chrome,dialog,modal,resizable=no", args);
@ -646,7 +652,7 @@ let Utils = {
openShare: function Utils_openShare() {
Utils.openDialog("Share", "share.xul");
},
openLog: function Utils_openLog() {
Utils._openChromeWindow("Log", "log.xul");
},
@ -657,11 +663,11 @@ let Utils = {
openSync: function Utils_openSync() {
Utils._openChromeWindow("Sync", "pick-sync.xul");
},
openWizard: function Utils_openWizard() {
Utils._openChromeWindow("Wizard", "wizard.xul");
},
// assumes an nsIConverterInputStream
readStream: function Weave_readStream(is) {
let ret = "", str = {};
@ -738,3 +744,7 @@ Svc.Prefs = new Preferences(PREFS_BRANCH);
["WinMediator", "@mozilla.org/appshell/window-mediator;1", "nsIWindowMediator"],
["WinWatcher", "@mozilla.org/embedcomp/window-watcher;1", "nsIWindowWatcher"],
].forEach(function(lazy) Utils.lazySvc(Svc, lazy[0], lazy[1], Ci[lazy[2]]));
let Str = {};
["service", "about"]
.forEach(function(lazy) Utils.lazy2(Str, lazy, Utils.lazyStrings(lazy)));