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 the 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>
|
|
|
|
|
* Paul O’Shannessy <paul@oshannessy.com>
|
2010-09-07 18:37:46 -07:00
|
|
|
|
* Philipp von Weitershausen <philipp@weitershausen.de>
|
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 ***** */
|
|
|
|
|
|
|
|
|
|
Components.utils.import("resource://services-sync/service.js");
|
|
|
|
|
Components.utils.import("resource://gre/modules/Services.jsm");
|
|
|
|
|
|
|
|
|
|
const PAGE_NO_ACCOUNT = 0;
|
|
|
|
|
const PAGE_HAS_ACCOUNT = 1;
|
2011-01-11 23:50:13 -08:00
|
|
|
|
const PAGE_NEEDS_UPDATE = 2;
|
2010-08-02 16:37:56 -07:00
|
|
|
|
|
|
|
|
|
let gSyncPane = {
|
|
|
|
|
_stringBundle: null,
|
|
|
|
|
prefArray: ["engine.bookmarks", "engine.passwords", "engine.prefs",
|
|
|
|
|
"engine.tabs", "engine.history"],
|
|
|
|
|
|
|
|
|
|
get page() {
|
|
|
|
|
return document.getElementById("weavePrefsDeck").selectedIndex;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
set page(val) {
|
|
|
|
|
document.getElementById("weavePrefsDeck").selectedIndex = val;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
get _usingCustomServer() {
|
|
|
|
|
return Weave.Svc.Prefs.isSet("serverURL");
|
|
|
|
|
},
|
|
|
|
|
|
2011-01-11 23:50:13 -08:00
|
|
|
|
needsUpdate: function () {
|
|
|
|
|
this.page = PAGE_NEEDS_UPDATE;
|
2010-08-02 16:37:56 -07:00
|
|
|
|
let label = document.getElementById("loginError");
|
|
|
|
|
label.value = Weave.Utils.getErrorString(Weave.Status.login);
|
|
|
|
|
label.className = "error";
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
init: function () {
|
2011-01-11 23:50:13 -08:00
|
|
|
|
let topics = ["weave:service:login:error",
|
|
|
|
|
"weave:service:login:finish",
|
|
|
|
|
"weave:service:start-over",
|
|
|
|
|
"weave:service:setup-complete",
|
|
|
|
|
"weave:service:logout:finish"];
|
2010-08-02 16:37:56 -07:00
|
|
|
|
|
|
|
|
|
// Add the observers now and remove them on unload
|
2011-01-11 23:50:13 -08:00
|
|
|
|
//XXXzpao This should use Services.obs.* but Weave's Obs does nice handling
|
|
|
|
|
// of `this`. Fix in a followup. (bug 583347)
|
|
|
|
|
topics.forEach(function (topic) {
|
|
|
|
|
Weave.Svc.Obs.add(topic, this.updateWeavePrefs, this);
|
|
|
|
|
}, this);
|
|
|
|
|
window.addEventListener("unload", function() {
|
|
|
|
|
topics.forEach(function (topic) {
|
|
|
|
|
Weave.Svc.Obs.remove(topic, this.updateWeavePrefs, this);
|
|
|
|
|
}, gSyncPane);
|
|
|
|
|
}, false);
|
2010-08-02 16:37:56 -07:00
|
|
|
|
|
|
|
|
|
this._stringBundle =
|
2011-01-11 23:50:13 -08:00
|
|
|
|
Services.strings.createBundle("chrome://browser/locale/preferences/preferences.properties");
|
2010-08-02 16:37:56 -07:00
|
|
|
|
this.updateWeavePrefs();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
updateWeavePrefs: function () {
|
|
|
|
|
if (Weave.Status.service == Weave.CLIENT_NOT_CONFIGURED ||
|
2011-01-11 23:50:13 -08:00
|
|
|
|
Weave.Svc.Prefs.get("firstSync", "") == "notReady") {
|
2010-08-02 16:37:56 -07:00
|
|
|
|
this.page = PAGE_NO_ACCOUNT;
|
2011-01-11 23:50:13 -08:00
|
|
|
|
} else if (Weave.Status.login == Weave.LOGIN_FAILED_INVALID_PASSPHRASE ||
|
|
|
|
|
Weave.Status.login == Weave.LOGIN_FAILED_LOGIN_REJECTED) {
|
|
|
|
|
this.needsUpdate();
|
|
|
|
|
} else {
|
2010-08-02 16:37:56 -07:00
|
|
|
|
this.page = PAGE_HAS_ACCOUNT;
|
2011-01-11 23:50:13 -08:00
|
|
|
|
document.getElementById("accountName").value = Weave.Service.account;
|
2010-08-02 16:37:56 -07:00
|
|
|
|
document.getElementById("syncComputerName").value = Weave.Clients.localName;
|
|
|
|
|
document.getElementById("tosPP").hidden = this._usingCustomServer;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
startOver: function (showDialog) {
|
|
|
|
|
if (showDialog) {
|
|
|
|
|
let flags = Services.prompt.BUTTON_POS_0 * Services.prompt.BUTTON_TITLE_IS_STRING +
|
2011-04-29 01:21:06 -07:00
|
|
|
|
Services.prompt.BUTTON_POS_1 * Services.prompt.BUTTON_TITLE_CANCEL +
|
|
|
|
|
Services.prompt.BUTTON_POS_1_DEFAULT;
|
2010-08-02 16:37:56 -07:00
|
|
|
|
let buttonChoice =
|
|
|
|
|
Services.prompt.confirmEx(window,
|
2011-07-07 09:22:50 -07:00
|
|
|
|
this._stringBundle.GetStringFromName("syncUnlink.title"),
|
|
|
|
|
this._stringBundle.GetStringFromName("syncUnlink.label"),
|
2010-08-02 16:37:56 -07:00
|
|
|
|
flags,
|
2011-07-07 09:22:50 -07:00
|
|
|
|
this._stringBundle.GetStringFromName("syncUnlinkConfirm.label"),
|
2010-08-02 16:37:56 -07:00
|
|
|
|
null, null, null, {});
|
|
|
|
|
|
|
|
|
|
// If the user selects cancel, just bail
|
|
|
|
|
if (buttonChoice == 1)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Weave.Service.startOver();
|
|
|
|
|
this.updateWeavePrefs();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
updatePass: function () {
|
|
|
|
|
if (Weave.Status.login == Weave.LOGIN_FAILED_LOGIN_REJECTED)
|
|
|
|
|
gSyncUtils.changePassword();
|
|
|
|
|
else
|
|
|
|
|
gSyncUtils.updatePassphrase();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
resetPass: function () {
|
|
|
|
|
if (Weave.Status.login == Weave.LOGIN_FAILED_LOGIN_REJECTED)
|
|
|
|
|
gSyncUtils.resetPassword();
|
|
|
|
|
else
|
|
|
|
|
gSyncUtils.resetPassphrase();
|
|
|
|
|
},
|
|
|
|
|
|
2011-10-02 01:16:06 -07:00
|
|
|
|
/**
|
|
|
|
|
* Invoke the Sync setup wizard.
|
|
|
|
|
*
|
|
|
|
|
* @param wizardType
|
|
|
|
|
* Indicates type of wizard to launch:
|
|
|
|
|
* null -- regular set up wizard
|
|
|
|
|
* "pair" -- pair a device first
|
|
|
|
|
* "reset" -- reset sync
|
|
|
|
|
*/
|
|
|
|
|
openSetup: function (wizardType) {
|
2010-08-02 16:37:56 -07:00
|
|
|
|
var win = Services.wm.getMostRecentWindow("Weave:AccountSetup");
|
|
|
|
|
if (win)
|
|
|
|
|
win.focus();
|
|
|
|
|
else {
|
|
|
|
|
window.openDialog("chrome://browser/content/syncSetup.xul",
|
2011-10-02 01:16:06 -07:00
|
|
|
|
"weaveSetup", "centerscreen,chrome,resizable=no",
|
|
|
|
|
wizardType);
|
2010-08-02 16:37:56 -07:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2010-09-15 06:55:04 -07:00
|
|
|
|
openQuotaDialog: function () {
|
|
|
|
|
let win = Services.wm.getMostRecentWindow("Sync:ViewQuota");
|
|
|
|
|
if (win)
|
|
|
|
|
win.focus();
|
|
|
|
|
else
|
|
|
|
|
window.openDialog("chrome://browser/content/syncQuota.xul", "",
|
|
|
|
|
"centerscreen,chrome,dialog,modal");
|
|
|
|
|
},
|
|
|
|
|
|
2010-12-09 18:28:41 -08:00
|
|
|
|
openAddDevice: function () {
|
2011-01-13 21:43:25 -08:00
|
|
|
|
if (!Weave.Utils.ensureMPUnlocked())
|
|
|
|
|
return;
|
|
|
|
|
|
2010-12-09 18:28:41 -08:00
|
|
|
|
let win = Services.wm.getMostRecentWindow("Sync:AddDevice");
|
|
|
|
|
if (win)
|
|
|
|
|
win.focus();
|
|
|
|
|
else
|
|
|
|
|
window.openDialog("chrome://browser/content/syncAddDevice.xul",
|
|
|
|
|
"syncAddDevice", "centerscreen,chrome,resizable=no");
|
|
|
|
|
},
|
|
|
|
|
|
2010-08-02 16:37:56 -07:00
|
|
|
|
resetSync: function () {
|
2011-10-02 01:16:06 -07:00
|
|
|
|
this.openSetup("reset");
|
2010-08-02 16:37:56 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|