2010-08-02 16:37:56 -07: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 Weave.
|
|
|
|
|
*
|
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
|
* Mozilla Foundation.
|
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2009
|
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s):
|
|
|
|
|
* Edward Lee <edilee@mozilla.com>
|
|
|
|
|
* Mike Connor <mconnor@mozilla.com>
|
|
|
|
|
* Philipp von Weitershausen <philipp@weitershausen.de>
|
|
|
|
|
* Paul O’Shannessy <paul@oshannessy.com>
|
2011-02-03 10:53:59 -08:00
|
|
|
|
* Richard Newman <rnewman@mozilla.com>
|
2010-08-02 16:37:56 -07:00
|
|
|
|
*
|
|
|
|
|
* 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 ***** */
|
|
|
|
|
|
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
|
const Cr = Components.results;
|
|
|
|
|
const Cu = Components.utils;
|
|
|
|
|
|
|
|
|
|
// page consts
|
|
|
|
|
|
|
|
|
|
const INTRO_PAGE = 0;
|
|
|
|
|
const NEW_ACCOUNT_START_PAGE = 1;
|
|
|
|
|
const NEW_ACCOUNT_PP_PAGE = 2;
|
2010-09-07 18:37:46 -07:00
|
|
|
|
const NEW_ACCOUNT_CAPTCHA_PAGE = 3;
|
2010-12-09 18:28:25 -08:00
|
|
|
|
const EXISTING_ACCOUNT_CONNECT_PAGE = 4;
|
|
|
|
|
const EXISTING_ACCOUNT_LOGIN_PAGE = 5;
|
2010-09-07 18:37:46 -07:00
|
|
|
|
const OPTIONS_PAGE = 6;
|
|
|
|
|
const OPTIONS_CONFIRM_PAGE = 7;
|
|
|
|
|
const SETUP_SUCCESS_PAGE = 8;
|
2010-08-02 16:37:56 -07:00
|
|
|
|
|
2011-04-29 10:57:59 -07:00
|
|
|
|
// Broader than we'd like, but after this changed from api-secure.recaptcha.net
|
|
|
|
|
// we had no choice. At least we only do this for the duration of setup.
|
|
|
|
|
// See discussion in Bugs 508112 and 653307.
|
|
|
|
|
const RECAPTCHA_DOMAIN = "https://www.google.com";
|
|
|
|
|
|
2010-09-07 18:37:46 -07:00
|
|
|
|
Cu.import("resource://services-sync/main.js");
|
2010-08-02 16:37:56 -07:00
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2011-05-19 18:08:22 -07:00
|
|
|
|
Cu.import("resource://gre/modules/PlacesUtils.jsm");
|
2010-09-10 13:02:57 -07:00
|
|
|
|
Cu.import("resource://gre/modules/PluralForm.jsm");
|
2010-08-02 16:37:56 -07:00
|
|
|
|
|
|
|
|
|
var gSyncSetup = {
|
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports,
|
|
|
|
|
Ci.nsIWebProgressListener,
|
|
|
|
|
Ci.nsISupportsWeakReference]),
|
|
|
|
|
|
2011-06-06 11:29:54 -07:00
|
|
|
|
haveCaptcha: true,
|
2010-08-02 16:37:56 -07:00
|
|
|
|
captchaBrowser: null,
|
|
|
|
|
wizard: null,
|
|
|
|
|
_disabledSites: [],
|
|
|
|
|
|
|
|
|
|
status: {
|
|
|
|
|
password: false,
|
|
|
|
|
email: false,
|
|
|
|
|
server: false
|
|
|
|
|
},
|
|
|
|
|
|
2011-04-29 10:57:59 -07:00
|
|
|
|
get _remoteSites() [Weave.Service.serverURL, RECAPTCHA_DOMAIN],
|
|
|
|
|
|
2010-08-02 16:37:56 -07:00
|
|
|
|
get _usingMainServers() {
|
|
|
|
|
if (this._settingUpNew)
|
2010-12-09 18:28:25 -08:00
|
|
|
|
return document.getElementById("server").selectedIndex == 0;
|
|
|
|
|
return document.getElementById("existingServer").selectedIndex == 0;
|
2010-08-02 16:37:56 -07:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
init: function () {
|
|
|
|
|
let obs = [
|
|
|
|
|
["weave:service:changepph:finish", "onResetPassphrase"],
|
2011-05-11 17:58:05 -07:00
|
|
|
|
["weave:service:login:start", "onLoginStart"],
|
|
|
|
|
["weave:service:login:error", "onLoginEnd"],
|
|
|
|
|
["weave:service:login:finish", "onLoginEnd"]];
|
2010-08-02 16:37:56 -07:00
|
|
|
|
|
|
|
|
|
// Add the observers now and remove them on unload
|
|
|
|
|
let self = this;
|
|
|
|
|
let addRem = function(add) {
|
|
|
|
|
obs.forEach(function([topic, func]) {
|
|
|
|
|
//XXXzpao This should use Services.obs.* but Weave's Obs does nice handling
|
|
|
|
|
// of `this`. Fix in a followup. (bug 583347)
|
|
|
|
|
if (add)
|
|
|
|
|
Weave.Svc.Obs.add(topic, self[func], self);
|
|
|
|
|
else
|
|
|
|
|
Weave.Svc.Obs.remove(topic, self[func], self);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
addRem(true);
|
|
|
|
|
window.addEventListener("unload", function() addRem(false), false);
|
|
|
|
|
|
|
|
|
|
this.captchaBrowser = document.getElementById("captcha");
|
|
|
|
|
this.wizard = document.getElementById("accountSetup");
|
|
|
|
|
|
|
|
|
|
if (window.arguments && window.arguments[0] == true) {
|
|
|
|
|
// we're resetting sync
|
|
|
|
|
this._resettingSync = true;
|
2010-09-07 18:37:46 -07:00
|
|
|
|
this.wizard.pageIndex = OPTIONS_PAGE;
|
2010-08-02 16:37:56 -07:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
this.wizard.canAdvance = false;
|
|
|
|
|
this.captchaBrowser.addProgressListener(this);
|
|
|
|
|
Weave.Svc.Prefs.set("firstSync", "notReady");
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-07 18:37:46 -07:00
|
|
|
|
this.wizard.getButton("extra1").label =
|
|
|
|
|
this._stringBundle.GetStringFromName("button.syncOptions.label");
|
2010-08-02 16:37:56 -07:00
|
|
|
|
|
2010-09-07 18:37:46 -07:00
|
|
|
|
// Remember these values because the options pages change them temporarily.
|
|
|
|
|
this._nextButtonLabel = this.wizard.getButton("next").label;
|
|
|
|
|
this._nextButtonAccesskey = this.wizard.getButton("next")
|
|
|
|
|
.getAttribute("accesskey");
|
|
|
|
|
this._backButtonLabel = this.wizard.getButton("back").label;
|
|
|
|
|
this._backButtonAccesskey = this.wizard.getButton("back")
|
|
|
|
|
.getAttribute("accesskey");
|
2010-08-02 16:37:56 -07:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
startNewAccountSetup: function () {
|
2011-01-13 21:43:25 -08:00
|
|
|
|
if (!Weave.Utils.ensureMPUnlocked())
|
|
|
|
|
return false;
|
2010-08-02 16:37:56 -07:00
|
|
|
|
this._settingUpNew = true;
|
|
|
|
|
this.wizard.pageIndex = NEW_ACCOUNT_START_PAGE;
|
2011-06-06 11:29:54 -07:00
|
|
|
|
this.loadCaptcha();
|
2010-08-02 16:37:56 -07:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
useExistingAccount: function () {
|
2011-01-13 21:43:25 -08:00
|
|
|
|
if (!Weave.Utils.ensureMPUnlocked())
|
|
|
|
|
return false;
|
2010-08-02 16:37:56 -07:00
|
|
|
|
this._settingUpNew = false;
|
2010-12-09 18:28:25 -08:00
|
|
|
|
this.wizard.pageIndex = EXISTING_ACCOUNT_CONNECT_PAGE;
|
2010-08-02 16:37:56 -07:00
|
|
|
|
},
|
|
|
|
|
|
2011-02-03 10:53:59 -08:00
|
|
|
|
resetPassphrase: function resetPassphrase() {
|
|
|
|
|
// Apply the existing form fields so that
|
|
|
|
|
// Weave.Service.changePassphrase() has the necessary credentials.
|
|
|
|
|
Weave.Service.account = document.getElementById("existingAccountName").value;
|
|
|
|
|
Weave.Service.password = document.getElementById("existingPassword").value;
|
|
|
|
|
|
|
|
|
|
// Generate a new passphrase so that Weave.Service.login() will
|
|
|
|
|
// actually do something.
|
|
|
|
|
let passphrase = Weave.Utils.generatePassphrase();
|
|
|
|
|
Weave.Service.passphrase = passphrase;
|
|
|
|
|
|
|
|
|
|
// Only open the dialog if username + password are actually correct.
|
|
|
|
|
Weave.Service.login();
|
|
|
|
|
if ([Weave.LOGIN_FAILED_INVALID_PASSPHRASE,
|
|
|
|
|
Weave.LOGIN_FAILED_NO_PASSPHRASE,
|
|
|
|
|
Weave.LOGIN_SUCCEEDED].indexOf(Weave.Status.login) == -1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Hide any errors about the passphrase, we know it's not right.
|
|
|
|
|
let feedback = document.getElementById("existingPassphraseFeedbackRow");
|
|
|
|
|
feedback.hidden = true;
|
|
|
|
|
let el = document.getElementById("existingPassphrase");
|
|
|
|
|
el.value = Weave.Utils.hyphenatePassphrase(passphrase);
|
|
|
|
|
|
|
|
|
|
// changePassphrase() will sync, make sure we set the "firstSync" pref
|
|
|
|
|
// according to the user's pref.
|
|
|
|
|
Weave.Svc.Prefs.reset("firstSync");
|
|
|
|
|
this.setupInitialSync();
|
2011-02-03 10:54:00 -08:00
|
|
|
|
gSyncUtils.resetPassphrase(true);
|
2011-02-03 10:53:59 -08:00
|
|
|
|
},
|
|
|
|
|
|
2010-08-02 16:37:56 -07:00
|
|
|
|
onResetPassphrase: function () {
|
2010-11-30 20:39:32 -08:00
|
|
|
|
document.getElementById("existingPassphrase").value =
|
|
|
|
|
Weave.Utils.hyphenatePassphrase(Weave.Service.passphrase);
|
2011-02-03 10:53:59 -08:00
|
|
|
|
this.checkFields();
|
2010-08-02 16:37:56 -07:00
|
|
|
|
this.wizard.advance();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onLoginStart: function () {
|
|
|
|
|
this.toggleLoginFeedback(false);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onLoginEnd: function () {
|
|
|
|
|
this.toggleLoginFeedback(true);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
toggleLoginFeedback: function (stop) {
|
2010-12-09 18:28:25 -08:00
|
|
|
|
document.getElementById("login-throbber").hidden = stop;
|
|
|
|
|
let password = document.getElementById("existingPasswordFeedbackRow");
|
|
|
|
|
let server = document.getElementById("existingServerFeedbackRow");
|
|
|
|
|
let passphrase = document.getElementById("existingPassphraseFeedbackRow");
|
|
|
|
|
|
|
|
|
|
if (!stop || (Weave.Status.login == Weave.LOGIN_SUCCEEDED)) {
|
|
|
|
|
password.hidden = server.hidden = passphrase.hidden = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2010-08-02 16:37:56 -07:00
|
|
|
|
|
2010-12-09 18:28:25 -08:00
|
|
|
|
let feedback;
|
|
|
|
|
switch (Weave.Status.login) {
|
|
|
|
|
case Weave.LOGIN_FAILED_NETWORK_ERROR:
|
|
|
|
|
case Weave.LOGIN_FAILED_SERVER_ERROR:
|
|
|
|
|
feedback = server;
|
|
|
|
|
break;
|
|
|
|
|
case Weave.LOGIN_FAILED_LOGIN_REJECTED:
|
2011-05-11 17:58:05 -07:00
|
|
|
|
case Weave.LOGIN_FAILED_NO_USERNAME:
|
|
|
|
|
case Weave.LOGIN_FAILED_NO_PASSWORD:
|
2010-12-09 18:28:25 -08:00
|
|
|
|
feedback = password;
|
|
|
|
|
break;
|
|
|
|
|
case Weave.LOGIN_FAILED_INVALID_PASSPHRASE:
|
|
|
|
|
feedback = passphrase;
|
2010-08-02 16:37:56 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
2010-12-09 18:28:25 -08:00
|
|
|
|
this._setFeedbackMessage(feedback, false, Weave.Status.login);
|
2010-08-02 16:37:56 -07:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
setupInitialSync: function () {
|
|
|
|
|
let action = document.getElementById("mergeChoiceRadio").selectedItem.id;
|
|
|
|
|
switch (action) {
|
|
|
|
|
case "resetClient":
|
|
|
|
|
// if we're not resetting sync, we don't need to explicitly
|
|
|
|
|
// call resetClient
|
|
|
|
|
if (!this._resettingSync)
|
|
|
|
|
return;
|
|
|
|
|
// otherwise, fall through
|
|
|
|
|
case "wipeClient":
|
|
|
|
|
case "wipeRemote":
|
|
|
|
|
Weave.Svc.Prefs.set("firstSync", action);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// fun with validation!
|
|
|
|
|
checkFields: function () {
|
|
|
|
|
this.wizard.canAdvance = this.readyToAdvance();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
readyToAdvance: function () {
|
|
|
|
|
switch (this.wizard.pageIndex) {
|
|
|
|
|
case INTRO_PAGE:
|
|
|
|
|
return false;
|
|
|
|
|
case NEW_ACCOUNT_START_PAGE:
|
2011-01-13 21:43:25 -08:00
|
|
|
|
for (let i in this.status) {
|
2010-08-02 16:37:56 -07:00
|
|
|
|
if (!this.status[i])
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (this._usingMainServers)
|
|
|
|
|
return document.getElementById("tos").checked;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
case EXISTING_ACCOUNT_LOGIN_PAGE:
|
2010-09-15 06:55:04 -07:00
|
|
|
|
let hasUser = document.getElementById("existingAccountName").value != "";
|
2010-08-02 16:37:56 -07:00
|
|
|
|
let hasPass = document.getElementById("existingPassword").value != "";
|
2010-12-09 22:53:08 -08:00
|
|
|
|
let hasKey = document.getElementById("existingPassphrase").value != "";
|
2010-12-09 18:28:25 -08:00
|
|
|
|
|
|
|
|
|
if (hasUser && hasPass && hasKey) {
|
2010-08-02 16:37:56 -07:00
|
|
|
|
if (this._usingMainServers)
|
|
|
|
|
return true;
|
|
|
|
|
|
2011-06-06 11:29:54 -07:00
|
|
|
|
if (this._validateServer(document.getElementById("existingServer"))) {
|
2010-08-02 16:37:56 -07:00
|
|
|
|
return true;
|
2011-06-06 11:29:54 -07:00
|
|
|
|
}
|
2010-08-02 16:37:56 -07:00
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2010-12-09 18:28:25 -08:00
|
|
|
|
// Default, e.g. wizard's special page -1 etc.
|
2010-08-02 16:37:56 -07:00
|
|
|
|
return true;
|
|
|
|
|
},
|
|
|
|
|
|
2010-10-08 08:57:04 -07:00
|
|
|
|
onEmailInput: function () {
|
|
|
|
|
// Check account validity when the user stops typing for 1 second.
|
|
|
|
|
if (this._checkAccountTimer)
|
|
|
|
|
window.clearTimeout(this._checkAccountTimer);
|
|
|
|
|
this._checkAccountTimer = window.setTimeout(function () {
|
|
|
|
|
gSyncSetup.checkAccount();
|
|
|
|
|
}, 1000);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
checkAccount: function() {
|
|
|
|
|
delete this._checkAccountTimer;
|
2011-02-03 10:53:59 -08:00
|
|
|
|
let value = Weave.Utils.normalizeAccount(
|
|
|
|
|
document.getElementById("weaveEmail").value);
|
2010-09-15 06:55:04 -07:00
|
|
|
|
if (!value) {
|
|
|
|
|
this.status.email = false;
|
|
|
|
|
this.checkFields();
|
|
|
|
|
return;
|
2010-08-02 16:37:56 -07:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-15 06:55:04 -07:00
|
|
|
|
let re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
|
|
|
let feedback = document.getElementById("emailFeedbackRow");
|
|
|
|
|
let valid = re.test(value);
|
|
|
|
|
|
|
|
|
|
let str = "";
|
|
|
|
|
if (!valid) {
|
|
|
|
|
str = "invalidEmail.label";
|
|
|
|
|
} else {
|
|
|
|
|
let availCheck = Weave.Service.checkAccount(value);
|
|
|
|
|
valid = availCheck == "available";
|
|
|
|
|
if (!valid) {
|
|
|
|
|
if (availCheck == "notAvailable")
|
|
|
|
|
str = "usernameNotAvailable.label";
|
|
|
|
|
else
|
|
|
|
|
str = availCheck;
|
|
|
|
|
}
|
2010-08-02 16:37:56 -07:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-15 06:55:04 -07:00
|
|
|
|
this._setFeedbackMessage(feedback, valid, str);
|
|
|
|
|
this.status.email = valid;
|
|
|
|
|
if (valid)
|
|
|
|
|
Weave.Service.account = value;
|
2010-08-02 16:37:56 -07:00
|
|
|
|
this.checkFields();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onPasswordChange: function () {
|
|
|
|
|
let password = document.getElementById("weavePassword");
|
|
|
|
|
let valid, str;
|
|
|
|
|
if (password.value == document.getElementById("weavePassphrase").value) {
|
|
|
|
|
// xxxmpc - hack, sigh
|
|
|
|
|
valid = false;
|
2010-09-07 18:37:46 -07:00
|
|
|
|
errorString = Weave.Utils.getErrorString("change.password.pwSameAsSyncKey");
|
2010-08-02 16:37:56 -07:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
let pwconfirm = document.getElementById("weavePasswordConfirm");
|
|
|
|
|
[valid, errorString] = gSyncUtils.validatePassword(password, pwconfirm);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let feedback = document.getElementById("passwordFeedbackRow");
|
|
|
|
|
this._setFeedback(feedback, valid, errorString);
|
|
|
|
|
|
|
|
|
|
this.status.password = valid;
|
|
|
|
|
this.checkFields();
|
|
|
|
|
},
|
|
|
|
|
|
2010-09-07 18:37:46 -07:00
|
|
|
|
onPassphraseGenerate: function () {
|
2010-11-30 20:39:32 -08:00
|
|
|
|
let passphrase = Weave.Utils.generatePassphrase();
|
2010-09-07 18:37:46 -07:00
|
|
|
|
Weave.Service.passphrase = passphrase;
|
|
|
|
|
let el = document.getElementById("weavePassphrase");
|
2010-11-30 20:39:32 -08:00
|
|
|
|
el.value = Weave.Utils.hyphenatePassphrase(passphrase);
|
2010-08-02 16:37:56 -07:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onPageShow: function() {
|
|
|
|
|
switch (this.wizard.pageIndex) {
|
|
|
|
|
case INTRO_PAGE:
|
|
|
|
|
this.wizard.getButton("next").hidden = true;
|
|
|
|
|
this.wizard.getButton("back").hidden = true;
|
2010-09-07 18:37:46 -07:00
|
|
|
|
this.wizard.getButton("extra1").hidden = true;
|
2010-08-02 16:37:56 -07:00
|
|
|
|
break;
|
|
|
|
|
case NEW_ACCOUNT_PP_PAGE:
|
2010-10-14 02:12:33 -07:00
|
|
|
|
document.getElementById("saveSyncKeyButton").focus();
|
2010-09-07 18:37:46 -07:00
|
|
|
|
let el = document.getElementById("weavePassphrase");
|
|
|
|
|
if (!el.value)
|
|
|
|
|
this.onPassphraseGenerate();
|
2010-08-02 16:37:56 -07:00
|
|
|
|
this.checkFields();
|
|
|
|
|
break;
|
2011-06-06 11:29:54 -07:00
|
|
|
|
case NEW_ACCOUNT_CAPTCHA_PAGE:
|
|
|
|
|
if (!this.haveCaptcha) {
|
|
|
|
|
gSyncSetup.wizard.advance();
|
|
|
|
|
}
|
|
|
|
|
break;
|
2010-08-02 16:37:56 -07:00
|
|
|
|
case NEW_ACCOUNT_START_PAGE:
|
2010-09-07 18:37:46 -07:00
|
|
|
|
this.wizard.getButton("extra1").hidden = false;
|
2010-12-09 18:28:25 -08:00
|
|
|
|
this.wizard.getButton("next").hidden = false;
|
|
|
|
|
this.wizard.getButton("back").hidden = false;
|
|
|
|
|
this.onServerCommand();
|
|
|
|
|
this.wizard.canRewind = true;
|
2010-09-07 18:37:46 -07:00
|
|
|
|
this.checkFields();
|
2010-12-09 18:28:25 -08:00
|
|
|
|
break;
|
|
|
|
|
case EXISTING_ACCOUNT_CONNECT_PAGE:
|
2010-08-02 16:37:56 -07:00
|
|
|
|
this.wizard.getButton("next").hidden = false;
|
|
|
|
|
this.wizard.getButton("back").hidden = false;
|
2010-09-07 18:37:46 -07:00
|
|
|
|
this.wizard.getButton("extra1").hidden = false;
|
2011-01-06 17:29:58 -08:00
|
|
|
|
this.wizard.canAdvance = false;
|
2010-09-07 18:37:46 -07:00
|
|
|
|
this.wizard.canRewind = true;
|
2010-12-09 18:28:25 -08:00
|
|
|
|
this.startEasySetup();
|
2010-08-02 16:37:56 -07:00
|
|
|
|
break;
|
2010-12-09 18:28:25 -08:00
|
|
|
|
case EXISTING_ACCOUNT_LOGIN_PAGE:
|
|
|
|
|
this.wizard.canRewind = true;
|
2010-11-30 20:39:32 -08:00
|
|
|
|
this.checkFields();
|
|
|
|
|
break;
|
2010-08-02 16:37:56 -07:00
|
|
|
|
case SETUP_SUCCESS_PAGE:
|
|
|
|
|
this.wizard.canRewind = false;
|
2010-12-09 18:28:25 -08:00
|
|
|
|
this.wizard.canAdvance = true;
|
2010-08-02 16:37:56 -07:00
|
|
|
|
this.wizard.getButton("back").hidden = true;
|
2010-09-07 18:37:46 -07:00
|
|
|
|
this.wizard.getButton("next").hidden = true;
|
2010-08-02 16:37:56 -07:00
|
|
|
|
this.wizard.getButton("cancel").hidden = true;
|
2010-09-07 18:37:46 -07:00
|
|
|
|
this.wizard.getButton("finish").hidden = false;
|
|
|
|
|
this._handleSuccess();
|
|
|
|
|
break;
|
|
|
|
|
case OPTIONS_PAGE:
|
|
|
|
|
this.wizard.canRewind = false;
|
|
|
|
|
this.wizard.canAdvance = true;
|
|
|
|
|
if (!this._resettingSync) {
|
|
|
|
|
this.wizard.getButton("next").label =
|
|
|
|
|
this._stringBundle.GetStringFromName("button.syncOptionsDone.label");
|
|
|
|
|
this.wizard.getButton("next").removeAttribute("accesskey");
|
|
|
|
|
}
|
|
|
|
|
this.wizard.getButton("next").hidden = false;
|
|
|
|
|
this.wizard.getButton("back").hidden = true;
|
|
|
|
|
this.wizard.getButton("cancel").hidden = !this._resettingSync;
|
|
|
|
|
this.wizard.getButton("extra1").hidden = true;
|
|
|
|
|
document.getElementById("syncComputerName").value = Weave.Clients.localName;
|
|
|
|
|
document.getElementById("syncOptions").collapsed = this._resettingSync;
|
|
|
|
|
document.getElementById("mergeOptions").collapsed = this._settingUpNew;
|
|
|
|
|
break;
|
|
|
|
|
case OPTIONS_CONFIRM_PAGE:
|
|
|
|
|
this.wizard.canRewind = true;
|
|
|
|
|
this.wizard.canAdvance = true;
|
|
|
|
|
this.wizard.getButton("back").label =
|
|
|
|
|
this._stringBundle.GetStringFromName("button.syncOptionsCancel.label");
|
|
|
|
|
this.wizard.getButton("back").removeAttribute("accesskey");
|
|
|
|
|
this.wizard.getButton("back").hidden = this._resettingSync;
|
|
|
|
|
this.wizard.getButton("next").hidden = false;
|
|
|
|
|
this.wizard.getButton("finish").hidden = true;
|
2010-08-02 16:37:56 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onWizardAdvance: function () {
|
2011-01-13 21:43:25 -08:00
|
|
|
|
// Check pageIndex so we don't prompt before the Sync setup wizard appears.
|
|
|
|
|
// This is a fallback in case the Master Password gets locked mid-wizard.
|
|
|
|
|
if ((this.wizard.pageIndex >= 0) &&
|
|
|
|
|
!Weave.Utils.ensureMPUnlocked()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-02 16:37:56 -07:00
|
|
|
|
if (!this.wizard.pageIndex)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
switch (this.wizard.pageIndex) {
|
2010-10-08 08:57:04 -07:00
|
|
|
|
case NEW_ACCOUNT_START_PAGE:
|
|
|
|
|
// If the user selects Next (e.g. by hitting enter) when we haven't
|
|
|
|
|
// executed the delayed checks yet, execute them immediately.
|
|
|
|
|
if (this._checkAccountTimer)
|
|
|
|
|
this.checkAccount();
|
|
|
|
|
if (this._checkServerTimer)
|
|
|
|
|
this.checkServer();
|
|
|
|
|
return this.wizard.canAdvance;
|
2010-08-02 16:37:56 -07:00
|
|
|
|
case NEW_ACCOUNT_CAPTCHA_PAGE:
|
|
|
|
|
let doc = this.captchaBrowser.contentDocument;
|
|
|
|
|
let getField = function getField(field) {
|
|
|
|
|
let node = doc.getElementById("recaptcha_" + field + "_field");
|
|
|
|
|
return node && node.value;
|
|
|
|
|
};
|
|
|
|
|
|
2010-09-07 18:37:46 -07:00
|
|
|
|
// Display throbber
|
|
|
|
|
let feedback = document.getElementById("captchaFeedback");
|
|
|
|
|
let image = feedback.firstChild;
|
|
|
|
|
let label = image.nextSibling;
|
|
|
|
|
image.setAttribute("status", "active");
|
|
|
|
|
label.value = this._stringBundle.GetStringFromName("verifying.label");
|
|
|
|
|
feedback.hidden = false;
|
|
|
|
|
|
2010-08-02 16:37:56 -07:00
|
|
|
|
let password = document.getElementById("weavePassword").value;
|
2011-02-03 10:53:59 -08:00
|
|
|
|
let email = Weave.Utils.normalizeAccount(
|
|
|
|
|
document.getElementById("weaveEmail").value);
|
2010-08-02 16:37:56 -07:00
|
|
|
|
let challenge = getField("challenge");
|
|
|
|
|
let response = getField("response");
|
|
|
|
|
|
2010-09-15 06:55:04 -07:00
|
|
|
|
let error = Weave.Service.createAccount(email, password,
|
2010-08-02 16:37:56 -07:00
|
|
|
|
challenge, response);
|
|
|
|
|
|
|
|
|
|
if (error == null) {
|
2010-09-15 06:55:04 -07:00
|
|
|
|
Weave.Service.account = email;
|
2010-08-02 16:37:56 -07:00
|
|
|
|
Weave.Service.password = password;
|
|
|
|
|
this._handleNoScript(false);
|
|
|
|
|
this.wizard.pageIndex = SETUP_SUCCESS_PAGE;
|
2010-09-07 18:37:46 -07:00
|
|
|
|
return false;
|
2010-08-02 16:37:56 -07:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-07 18:37:46 -07:00
|
|
|
|
image.setAttribute("status", "error");
|
|
|
|
|
label.value = Weave.Utils.getErrorString(error);
|
2010-08-02 16:37:56 -07:00
|
|
|
|
return false;
|
|
|
|
|
case EXISTING_ACCOUNT_LOGIN_PAGE:
|
2011-02-03 10:53:59 -08:00
|
|
|
|
Weave.Service.account = Weave.Utils.normalizeAccount(
|
|
|
|
|
document.getElementById("existingAccountName").value);
|
2010-08-02 16:37:56 -07:00
|
|
|
|
Weave.Service.password = document.getElementById("existingPassword").value;
|
2010-09-07 18:37:46 -07:00
|
|
|
|
let pp = document.getElementById("existingPassphrase").value;
|
2010-11-30 20:39:32 -08:00
|
|
|
|
Weave.Service.passphrase = Weave.Utils.normalizePassphrase(pp);
|
2010-08-02 16:37:56 -07:00
|
|
|
|
if (Weave.Service.login())
|
2010-09-07 18:37:46 -07:00
|
|
|
|
this.wizard.pageIndex = SETUP_SUCCESS_PAGE;
|
2010-08-02 16:37:56 -07:00
|
|
|
|
return false;
|
2010-09-07 18:37:46 -07:00
|
|
|
|
case OPTIONS_PAGE:
|
|
|
|
|
let desc = document.getElementById("mergeChoiceRadio").selectedIndex;
|
|
|
|
|
// No confirmation needed on new account setup or merge option
|
|
|
|
|
// with existing account.
|
|
|
|
|
if (this._settingUpNew || (!this._resettingSync && desc == 0))
|
|
|
|
|
return this.returnFromOptions();
|
2010-08-02 16:37:56 -07:00
|
|
|
|
return this._handleChoice();
|
2010-09-07 18:37:46 -07:00
|
|
|
|
case OPTIONS_CONFIRM_PAGE:
|
2010-08-02 16:37:56 -07:00
|
|
|
|
if (this._resettingSync) {
|
|
|
|
|
this.onWizardFinish();
|
|
|
|
|
window.close();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2010-09-07 18:37:46 -07:00
|
|
|
|
return this.returnFromOptions();
|
2010-08-02 16:37:56 -07:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onWizardBack: function () {
|
|
|
|
|
switch (this.wizard.pageIndex) {
|
|
|
|
|
case NEW_ACCOUNT_START_PAGE:
|
|
|
|
|
case EXISTING_ACCOUNT_LOGIN_PAGE:
|
|
|
|
|
this.wizard.pageIndex = INTRO_PAGE;
|
|
|
|
|
return false;
|
2010-12-09 18:28:25 -08:00
|
|
|
|
case EXISTING_ACCOUNT_CONNECT_PAGE:
|
|
|
|
|
this.abortEasySetup();
|
|
|
|
|
this.wizard.pageIndex = INTRO_PAGE;
|
2010-08-02 16:37:56 -07:00
|
|
|
|
return false;
|
2010-09-07 18:37:46 -07:00
|
|
|
|
case OPTIONS_CONFIRM_PAGE:
|
|
|
|
|
// Backing up from the confirmation page = resetting first sync to merge.
|
|
|
|
|
document.getElementById("mergeChoiceRadio").selectedIndex = 0;
|
|
|
|
|
return this.returnFromOptions();
|
2010-08-02 16:37:56 -07:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onWizardFinish: function () {
|
2010-09-07 18:37:46 -07:00
|
|
|
|
this.setupInitialSync();
|
2010-08-02 16:37:56 -07:00
|
|
|
|
|
|
|
|
|
if (!this._resettingSync) {
|
|
|
|
|
function isChecked(element) {
|
|
|
|
|
return document.getElementById(element).hasAttribute("checked");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let prefs = ["engine.bookmarks", "engine.passwords", "engine.history", "engine.tabs", "engine.prefs"];
|
|
|
|
|
for (let i = 0;i < prefs.length;i++) {
|
|
|
|
|
Weave.Svc.Prefs.set(prefs[i], isChecked(prefs[i]));
|
|
|
|
|
}
|
|
|
|
|
this._handleNoScript(false);
|
|
|
|
|
if (Weave.Svc.Prefs.get("firstSync", "") == "notReady")
|
|
|
|
|
Weave.Svc.Prefs.reset("firstSync");
|
|
|
|
|
|
|
|
|
|
Weave.Service.persistLogin();
|
|
|
|
|
Weave.Svc.Obs.notify("weave:service:setup-complete");
|
|
|
|
|
if (this._settingUpNew)
|
|
|
|
|
gSyncUtils.openFirstClientFirstrun();
|
|
|
|
|
else
|
|
|
|
|
gSyncUtils.openAddedClientFirstrun();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Weave.Service.syncOnIdle(1);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onWizardCancel: function () {
|
|
|
|
|
if (this._resettingSync)
|
|
|
|
|
return;
|
|
|
|
|
|
2010-09-07 18:37:46 -07:00
|
|
|
|
if (this.wizard.pageIndex == SETUP_SUCCESS_PAGE) {
|
2010-08-02 16:37:56 -07:00
|
|
|
|
this.onWizardFinish();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2010-12-09 18:28:25 -08:00
|
|
|
|
this.abortEasySetup();
|
2010-08-02 16:37:56 -07:00
|
|
|
|
this._handleNoScript(false);
|
|
|
|
|
Weave.Service.startOver();
|
|
|
|
|
},
|
|
|
|
|
|
2010-09-07 18:37:46 -07:00
|
|
|
|
onSyncOptions: function () {
|
|
|
|
|
this._beforeOptionsPage = this.wizard.pageIndex;
|
|
|
|
|
this.wizard.pageIndex = OPTIONS_PAGE;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
returnFromOptions: function() {
|
|
|
|
|
this.wizard.getButton("next").label = this._nextButtonLabel;
|
|
|
|
|
this.wizard.getButton("next").setAttribute("accesskey",
|
|
|
|
|
this._nextButtonAccesskey);
|
|
|
|
|
this.wizard.getButton("back").label = this._backButtonLabel;
|
|
|
|
|
this.wizard.getButton("back").setAttribute("accesskey",
|
|
|
|
|
this._backButtonAccesskey);
|
|
|
|
|
this.wizard.getButton("cancel").hidden = false;
|
|
|
|
|
this.wizard.getButton("extra1").hidden = false;
|
|
|
|
|
this.wizard.pageIndex = this._beforeOptionsPage;
|
|
|
|
|
return false;
|
|
|
|
|
},
|
|
|
|
|
|
2010-12-09 18:28:25 -08:00
|
|
|
|
startEasySetup: function () {
|
|
|
|
|
// Don't do anything if we have a client already (e.g. we went to
|
|
|
|
|
// Sync Options and just came back).
|
|
|
|
|
if (this._jpakeclient)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
let self = this;
|
|
|
|
|
this._jpakeclient = new Weave.JPAKEClient({
|
|
|
|
|
displayPIN: function displayPIN(pin) {
|
|
|
|
|
document.getElementById("easySetupPIN1").value = pin.slice(0, 4);
|
|
|
|
|
document.getElementById("easySetupPIN2").value = pin.slice(4, 8);
|
|
|
|
|
document.getElementById("easySetupPIN3").value = pin.slice(8);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onComplete: function onComplete(credentials) {
|
|
|
|
|
Weave.Service.account = credentials.account;
|
|
|
|
|
Weave.Service.password = credentials.password;
|
|
|
|
|
Weave.Service.passphrase = credentials.synckey;
|
|
|
|
|
Weave.Service.serverURL = credentials.serverURL;
|
|
|
|
|
self.wizard.pageIndex = SETUP_SUCCESS_PAGE;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onAbort: function onAbort(error) {
|
|
|
|
|
delete self._jpakeclient;
|
|
|
|
|
|
|
|
|
|
// No error means manual abort, e.g. wizard is aborted. Ignore.
|
|
|
|
|
if (!error)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Automatically go to manual setup if we couldn't acquire a channel.
|
|
|
|
|
if (error == Weave.JPAKE_ERROR_CHANNEL) {
|
|
|
|
|
self.wizard.pageIndex = EXISTING_ACCOUNT_LOGIN_PAGE;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Restart on all other errors.
|
|
|
|
|
self.startEasySetup();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
this._jpakeclient.receiveNoPIN();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
abortEasySetup: function () {
|
|
|
|
|
document.getElementById("easySetupPIN1").value = "";
|
|
|
|
|
document.getElementById("easySetupPIN2").value = "";
|
|
|
|
|
document.getElementById("easySetupPIN3").value = "";
|
|
|
|
|
if (!this._jpakeclient)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
this._jpakeclient.abort();
|
|
|
|
|
delete this._jpakeclient;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
manualSetup: function () {
|
|
|
|
|
this.abortEasySetup();
|
|
|
|
|
this.wizard.pageIndex = EXISTING_ACCOUNT_LOGIN_PAGE;
|
|
|
|
|
},
|
|
|
|
|
|
2010-08-02 16:37:56 -07:00
|
|
|
|
// _handleNoScript is needed because it blocks the captcha. So we temporarily
|
|
|
|
|
// allow the necessary sites so that we can verify the user is in fact a human.
|
|
|
|
|
// This was done with the help of Giorgio (NoScript author). See bug 508112.
|
|
|
|
|
_handleNoScript: function (addExceptions) {
|
|
|
|
|
// if NoScript isn't installed, or is disabled, bail out.
|
|
|
|
|
let ns = Cc["@maone.net/noscript-service;1"];
|
|
|
|
|
if (ns == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ns = ns.getService().wrappedJSObject;
|
|
|
|
|
if (addExceptions) {
|
|
|
|
|
this._remoteSites.forEach(function(site) {
|
|
|
|
|
site = ns.getSite(site);
|
|
|
|
|
if (!ns.isJSEnabled(site)) {
|
|
|
|
|
this._disabledSites.push(site); // save status
|
|
|
|
|
ns.setJSEnabled(site, true); // allow site
|
|
|
|
|
}
|
|
|
|
|
}, this);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
this._disabledSites.forEach(function(site) {
|
|
|
|
|
ns.setJSEnabled(site, false);
|
|
|
|
|
});
|
|
|
|
|
this._disabledSites = [];
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2010-12-09 18:28:25 -08:00
|
|
|
|
onExistingServerCommand: function () {
|
|
|
|
|
let control = document.getElementById("existingServer");
|
|
|
|
|
if (control.selectedIndex == 0) {
|
|
|
|
|
control.removeAttribute("editable");
|
|
|
|
|
Weave.Svc.Prefs.reset("serverURL");
|
|
|
|
|
} else {
|
|
|
|
|
control.setAttribute("editable", "true");
|
|
|
|
|
// Force a style flush to ensure that the binding is attached.
|
|
|
|
|
control.clientTop;
|
|
|
|
|
control.value = "";
|
|
|
|
|
control.inputField.focus();
|
2010-08-02 16:37:56 -07:00
|
|
|
|
}
|
2010-12-09 18:28:25 -08:00
|
|
|
|
document.getElementById("existingServerFeedbackRow").hidden = true;
|
|
|
|
|
this.checkFields();
|
|
|
|
|
},
|
2010-08-02 16:37:56 -07:00
|
|
|
|
|
2010-12-09 18:28:25 -08:00
|
|
|
|
onExistingServerInput: function () {
|
|
|
|
|
// Check custom server validity when the user stops typing for 1 second.
|
|
|
|
|
if (this._existingServerTimer)
|
|
|
|
|
window.clearTimeout(this._existingServerTimer);
|
|
|
|
|
this._existingServerTimer = window.setTimeout(function () {
|
|
|
|
|
gSyncSetup.checkFields();
|
|
|
|
|
}, 1000);
|
|
|
|
|
},
|
2010-08-02 16:37:56 -07:00
|
|
|
|
|
2010-12-09 18:28:25 -08:00
|
|
|
|
onServerCommand: function () {
|
|
|
|
|
document.getElementById("TOSRow").hidden = !this._usingMainServers;
|
|
|
|
|
let control = document.getElementById("server");
|
2010-10-08 08:57:04 -07:00
|
|
|
|
if (!this._usingMainServers) {
|
2010-12-09 18:28:25 -08:00
|
|
|
|
control.setAttribute("editable", "true");
|
|
|
|
|
// Force a style flush to ensure that the binding is attached.
|
|
|
|
|
control.clientTop;
|
|
|
|
|
control.value = "";
|
|
|
|
|
control.inputField.focus();
|
|
|
|
|
// checkServer() will call checkAccount() and checkFields().
|
2010-10-08 08:57:04 -07:00
|
|
|
|
this.checkServer();
|
|
|
|
|
return;
|
2010-08-02 16:37:56 -07:00
|
|
|
|
}
|
2010-12-09 18:28:25 -08:00
|
|
|
|
control.removeAttribute("editable");
|
2010-10-08 08:57:04 -07:00
|
|
|
|
Weave.Svc.Prefs.reset("serverURL");
|
2011-06-06 11:29:54 -07:00
|
|
|
|
if (this._settingUpNew) {
|
|
|
|
|
this.loadCaptcha();
|
|
|
|
|
}
|
2010-10-08 08:57:04 -07:00
|
|
|
|
this.checkAccount();
|
|
|
|
|
this.status.server = true;
|
|
|
|
|
document.getElementById("serverFeedbackRow").hidden = true;
|
|
|
|
|
this.checkFields();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onServerInput: function () {
|
|
|
|
|
// Check custom server validity when the user stops typing for 1 second.
|
|
|
|
|
if (this._checkServerTimer)
|
|
|
|
|
window.clearTimeout(this._checkServerTimer);
|
|
|
|
|
this._checkServerTimer = window.setTimeout(function () {
|
|
|
|
|
gSyncSetup.checkServer();
|
|
|
|
|
}, 1000);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
checkServer: function () {
|
|
|
|
|
delete this._checkServerTimer;
|
2010-12-09 18:28:25 -08:00
|
|
|
|
let el = document.getElementById("server");
|
2010-10-08 08:57:04 -07:00
|
|
|
|
let valid = false;
|
|
|
|
|
let feedback = document.getElementById("serverFeedbackRow");
|
|
|
|
|
let str = "";
|
|
|
|
|
if (el.value) {
|
2011-06-06 11:29:54 -07:00
|
|
|
|
valid = this._validateServer(el);
|
2010-10-08 08:57:04 -07:00
|
|
|
|
let str = valid ? "" : "serverInvalid.label";
|
|
|
|
|
this._setFeedbackMessage(feedback, valid, str);
|
2010-08-02 16:37:56 -07:00
|
|
|
|
}
|
2010-10-08 08:57:04 -07:00
|
|
|
|
else
|
|
|
|
|
this._setFeedbackMessage(feedback, true);
|
2010-08-02 16:37:56 -07:00
|
|
|
|
|
2010-09-15 06:55:04 -07:00
|
|
|
|
// Recheck account against the new server.
|
2010-08-02 16:37:56 -07:00
|
|
|
|
if (valid)
|
2010-10-08 08:57:04 -07:00
|
|
|
|
this.checkAccount();
|
2010-08-02 16:37:56 -07:00
|
|
|
|
|
|
|
|
|
this.status.server = valid;
|
|
|
|
|
this.checkFields();
|
|
|
|
|
},
|
|
|
|
|
|
2011-06-06 11:29:54 -07:00
|
|
|
|
_validateServer: function (element) {
|
2010-08-02 16:37:56 -07:00
|
|
|
|
let valid = false;
|
|
|
|
|
let val = element.value;
|
|
|
|
|
if (!val)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
let uri = Weave.Utils.makeURI(val);
|
|
|
|
|
|
|
|
|
|
if (!uri)
|
|
|
|
|
uri = Weave.Utils.makeURI("https://" + val);
|
|
|
|
|
|
2011-06-06 11:29:54 -07:00
|
|
|
|
if (uri && this._settingUpNew) {
|
2010-08-02 16:37:56 -07:00
|
|
|
|
function isValid(uri) {
|
|
|
|
|
Weave.Service.serverURL = uri.spec;
|
2010-09-15 06:55:04 -07:00
|
|
|
|
let check = Weave.Service.checkAccount("a");
|
2010-08-02 16:37:56 -07:00
|
|
|
|
return (check == "available" || check == "notAvailable");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (uri.schemeIs("http")) {
|
2010-08-28 13:42:29 -07:00
|
|
|
|
uri.scheme = "https";
|
|
|
|
|
if (isValid(uri))
|
2010-08-02 16:37:56 -07:00
|
|
|
|
valid = true;
|
2010-08-28 13:42:29 -07:00
|
|
|
|
else
|
|
|
|
|
// setting the scheme back to http
|
|
|
|
|
uri.scheme = "http";
|
2010-08-02 16:37:56 -07:00
|
|
|
|
}
|
|
|
|
|
if (!valid)
|
|
|
|
|
valid = isValid(uri);
|
2011-06-06 11:29:54 -07:00
|
|
|
|
|
|
|
|
|
if (valid) {
|
|
|
|
|
this.loadCaptcha();
|
|
|
|
|
}
|
2010-08-02 16:37:56 -07:00
|
|
|
|
}
|
|
|
|
|
else if (uri) {
|
|
|
|
|
valid = true;
|
|
|
|
|
Weave.Service.serverURL = uri.spec;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (valid)
|
|
|
|
|
element.value = Weave.Service.serverURL;
|
|
|
|
|
else
|
|
|
|
|
Weave.Svc.Prefs.reset("serverURL");
|
|
|
|
|
|
|
|
|
|
return valid;
|
|
|
|
|
},
|
|
|
|
|
|
2010-09-07 18:37:46 -07:00
|
|
|
|
_handleSuccess: function() {
|
|
|
|
|
let self = this;
|
|
|
|
|
function fill(id, string)
|
|
|
|
|
document.getElementById(id).firstChild.nodeValue =
|
|
|
|
|
string ? self._stringBundle.GetStringFromName(string) : "";
|
|
|
|
|
|
|
|
|
|
fill("firstSyncAction", "");
|
|
|
|
|
fill("firstSyncActionWarning", "");
|
|
|
|
|
if (this._settingUpNew) {
|
|
|
|
|
fill("firstSyncAction", "newAccount.action.label");
|
|
|
|
|
fill("firstSyncActionChange", "newAccount.change.label");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
fill("firstSyncActionChange", "existingAccount.change.label");
|
|
|
|
|
let action = document.getElementById("mergeChoiceRadio").selectedItem.id;
|
|
|
|
|
let id = action == "resetClient" ? "firstSyncAction" : "firstSyncActionWarning";
|
|
|
|
|
fill(id, action + ".change.label");
|
|
|
|
|
},
|
|
|
|
|
|
2010-08-02 16:37:56 -07:00
|
|
|
|
_handleChoice: function () {
|
|
|
|
|
let desc = document.getElementById("mergeChoiceRadio").selectedIndex;
|
|
|
|
|
document.getElementById("chosenActionDeck").selectedIndex = desc;
|
|
|
|
|
switch (desc) {
|
|
|
|
|
case 1:
|
|
|
|
|
if (this._case1Setup)
|
|
|
|
|
break;
|
|
|
|
|
|
2011-05-19 18:08:22 -07:00
|
|
|
|
let places_db = PlacesUtils.history
|
|
|
|
|
.QueryInterface(Ci.nsPIPlacesDatabase)
|
|
|
|
|
.DBConnection;
|
2010-11-10 09:36:47 -08:00
|
|
|
|
if (Weave.Engines.get("history").enabled) {
|
|
|
|
|
let daysOfHistory = 0;
|
|
|
|
|
let stm = places_db.createStatement(
|
|
|
|
|
"SELECT ROUND(( " +
|
|
|
|
|
"strftime('%s','now','localtime','utc') - " +
|
|
|
|
|
"( " +
|
|
|
|
|
"SELECT visit_date FROM moz_historyvisits " +
|
|
|
|
|
"ORDER BY visit_date ASC LIMIT 1 " +
|
|
|
|
|
")/1000000 " +
|
|
|
|
|
")/86400) AS daysOfHistory ");
|
|
|
|
|
|
|
|
|
|
if (stm.step())
|
|
|
|
|
daysOfHistory = stm.getInt32(0);
|
|
|
|
|
// Support %S for historical reasons (see bug 600141)
|
|
|
|
|
document.getElementById("historyCount").value =
|
|
|
|
|
PluralForm.get(daysOfHistory,
|
|
|
|
|
this._stringBundle.GetStringFromName("historyDaysCount.label"))
|
|
|
|
|
.replace("%S", daysOfHistory)
|
|
|
|
|
.replace("#1", daysOfHistory);
|
|
|
|
|
} else {
|
|
|
|
|
document.getElementById("historyCount").hidden = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Weave.Engines.get("bookmarks").enabled) {
|
|
|
|
|
let bookmarks = 0;
|
|
|
|
|
let stm = places_db.createStatement(
|
|
|
|
|
"SELECT count(*) AS bookmarks " +
|
|
|
|
|
"FROM moz_bookmarks b " +
|
|
|
|
|
"LEFT JOIN moz_bookmarks t ON " +
|
|
|
|
|
"b.parent = t.id WHERE b.type = 1 AND t.parent <> :tag");
|
2011-05-19 18:08:22 -07:00
|
|
|
|
stm.params.tag = PlacesUtils.tagsFolderId;
|
2010-11-10 09:36:47 -08:00
|
|
|
|
if (stm.executeStep())
|
|
|
|
|
bookmarks = stm.row.bookmarks;
|
|
|
|
|
// Support %S for historical reasons (see bug 600141)
|
|
|
|
|
document.getElementById("bookmarkCount").value =
|
|
|
|
|
PluralForm.get(bookmarks,
|
|
|
|
|
this._stringBundle.GetStringFromName("bookmarksCount.label"))
|
|
|
|
|
.replace("%S", bookmarks)
|
|
|
|
|
.replace("#1", bookmarks);
|
|
|
|
|
} else {
|
|
|
|
|
document.getElementById("bookmarkCount").hidden = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Weave.Engines.get("passwords").enabled) {
|
2011-05-19 18:08:07 -07:00
|
|
|
|
let logins = Services.logins.getAllLogins({});
|
2010-11-10 09:36:47 -08:00
|
|
|
|
// Support %S for historical reasons (see bug 600141)
|
|
|
|
|
document.getElementById("passwordCount").value =
|
|
|
|
|
PluralForm.get(logins.length,
|
|
|
|
|
this._stringBundle.GetStringFromName("passwordsCount.label"))
|
|
|
|
|
.replace("%S", logins.length)
|
|
|
|
|
.replace("#1", logins.length);
|
|
|
|
|
} else {
|
|
|
|
|
document.getElementById("passwordCount").hidden = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!Weave.Engines.get("prefs").enabled) {
|
|
|
|
|
document.getElementById("prefsWipe").hidden = true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-02 16:37:56 -07:00
|
|
|
|
this._case1Setup = true;
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
if (this._case2Setup)
|
|
|
|
|
break;
|
|
|
|
|
let count = 0;
|
|
|
|
|
function appendNode(label) {
|
|
|
|
|
let box = document.getElementById("clientList");
|
|
|
|
|
let node = document.createElement("label");
|
|
|
|
|
node.setAttribute("value", label);
|
|
|
|
|
node.setAttribute("class", "data indent");
|
|
|
|
|
box.appendChild(node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for each (let name in Weave.Clients.stats.names) {
|
|
|
|
|
// Don't list the current client
|
|
|
|
|
if (name == Weave.Clients.localName)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Only show the first several client names
|
|
|
|
|
if (++count <= 5)
|
|
|
|
|
appendNode(name);
|
|
|
|
|
}
|
|
|
|
|
if (count > 5) {
|
2010-09-28 10:19:43 -07:00
|
|
|
|
// Support %S for historical reasons (see bug 600141)
|
2010-08-02 16:37:56 -07:00
|
|
|
|
let label =
|
2010-09-10 13:02:57 -07:00
|
|
|
|
PluralForm.get(count - 5,
|
|
|
|
|
this._stringBundle.GetStringFromName("additionalClientCount.label"))
|
2010-09-28 10:19:43 -07:00
|
|
|
|
.replace("%S", count - 5)
|
|
|
|
|
.replace("#1", count - 5);
|
2010-08-02 16:37:56 -07:00
|
|
|
|
appendNode(label);
|
|
|
|
|
}
|
|
|
|
|
this._case2Setup = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// sets class and string on a feedback element
|
|
|
|
|
// if no property string is passed in, we clear label/style
|
|
|
|
|
_setFeedback: function (element, success, string) {
|
|
|
|
|
element.hidden = success || !string;
|
2011-01-22 17:46:22 -08:00
|
|
|
|
let classname = success ? "success" : "error";
|
2010-12-09 18:28:25 -08:00
|
|
|
|
let image = element.getElementsByAttribute("class", "statusIcon")[0];
|
2011-01-22 17:46:22 -08:00
|
|
|
|
image.setAttribute("status", classname);
|
2010-12-09 18:28:25 -08:00
|
|
|
|
let label = element.getElementsByAttribute("class", "status")[0];
|
2010-08-02 16:37:56 -07:00
|
|
|
|
label.value = string;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// shim
|
|
|
|
|
_setFeedbackMessage: function (element, success, string) {
|
|
|
|
|
let str = "";
|
|
|
|
|
if (string) {
|
|
|
|
|
try {
|
|
|
|
|
str = this._stringBundle.GetStringFromName(string);
|
|
|
|
|
} catch(e) {}
|
|
|
|
|
|
|
|
|
|
if (!str)
|
|
|
|
|
str = Weave.Utils.getErrorString(string);
|
|
|
|
|
}
|
|
|
|
|
this._setFeedback(element, success, str);
|
|
|
|
|
},
|
|
|
|
|
|
2011-06-06 11:29:54 -07:00
|
|
|
|
loadCaptcha: function loadCaptcha() {
|
|
|
|
|
// First check for NoScript and whitelist the right sites.
|
|
|
|
|
this._handleNoScript(true);
|
|
|
|
|
this.captchaBrowser.loadURI(Weave.Service.miscAPI + "captcha_html");
|
|
|
|
|
},
|
|
|
|
|
|
2010-08-02 16:37:56 -07:00
|
|
|
|
onStateChange: function(webProgress, request, stateFlags, status) {
|
|
|
|
|
// We're only looking for the end of the frame load
|
|
|
|
|
if ((stateFlags & Ci.nsIWebProgressListener.STATE_STOP) == 0)
|
|
|
|
|
return;
|
|
|
|
|
if ((stateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK) == 0)
|
|
|
|
|
return;
|
|
|
|
|
if ((stateFlags & Ci.nsIWebProgressListener.STATE_IS_WINDOW) == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// If we didn't find the captcha, assume it's not needed and move on
|
2011-06-06 11:29:54 -07:00
|
|
|
|
if (request.QueryInterface(Ci.nsIHttpChannel).responseStatus == 404) {
|
|
|
|
|
this.haveCaptcha = false;
|
|
|
|
|
// Hide the browser just in case we end up displaying the captcha page
|
|
|
|
|
// due to a sign up error.
|
|
|
|
|
this.captchaBrowser.hidden = true;
|
|
|
|
|
if (this.wizard.pageIndex == NEW_ACCOUNT_CAPTCHA_PAGE) {
|
|
|
|
|
this.onWizardAdvance();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
this.haveCaptcha = true;
|
|
|
|
|
this.captchaBrowser.hidden = false;
|
|
|
|
|
}
|
2010-08-02 16:37:56 -07:00
|
|
|
|
},
|
|
|
|
|
onProgressChange: function() {},
|
|
|
|
|
onStatusChange: function() {},
|
|
|
|
|
onSecurityChange: function() {},
|
|
|
|
|
onLocationChange: function () {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// onWizardAdvance() and onPageShow() are run before init(), so we'll set
|
|
|
|
|
// wizard & _stringBundle up as lazy getters.
|
|
|
|
|
XPCOMUtils.defineLazyGetter(gSyncSetup, "wizard", function() {
|
|
|
|
|
return document.getElementById("accountSetup");
|
|
|
|
|
});
|
|
|
|
|
XPCOMUtils.defineLazyGetter(gSyncSetup, "_stringBundle", function() {
|
|
|
|
|
return Services.strings.createBundle("chrome://browser/locale/syncSetup.properties");
|
|
|
|
|
});
|