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>
|
|
|
|
|
* 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 ***** */
|
|
|
|
|
|
|
|
|
|
// Weave should always exist before before this file gets included.
|
|
|
|
|
let gSyncUtils = {
|
2010-09-07 18:37:46 -07:00
|
|
|
|
get bundle() {
|
|
|
|
|
delete this.bundle;
|
|
|
|
|
return this.bundle = Services.strings.createBundle("chrome://browser/locale/syncSetup.properties");
|
|
|
|
|
},
|
|
|
|
|
|
2010-08-02 16:37:56 -07:00
|
|
|
|
// opens in a new window if we're in a modal prefwindow world, in a new tab otherwise
|
|
|
|
|
_openLink: function (url) {
|
|
|
|
|
let thisDocEl = document.documentElement,
|
|
|
|
|
openerDocEl = window.opener && window.opener.document.documentElement;
|
|
|
|
|
if (thisDocEl.id == "accountSetup" && window.opener &&
|
|
|
|
|
openerDocEl.id == "BrowserPreferences" && !openerDocEl.instantApply)
|
|
|
|
|
openUILinkIn(url, "window");
|
|
|
|
|
else if (thisDocEl.id == "BrowserPreferences" && !thisDocEl.instantApply)
|
|
|
|
|
openUILinkIn(url, "window");
|
2010-09-23 15:19:42 -07:00
|
|
|
|
else if (document.documentElement.id == "change-dialog")
|
2011-05-19 18:08:07 -07:00
|
|
|
|
Services.wm.getMostRecentWindow("navigator:browser")
|
|
|
|
|
.openUILinkIn(url, "tab");
|
2010-08-02 16:37:56 -07:00
|
|
|
|
else
|
|
|
|
|
openUILinkIn(url, "tab");
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
changeName: function changeName(input) {
|
|
|
|
|
// Make sure to update to a modified name, e.g., empty-string -> default
|
|
|
|
|
Weave.Clients.localName = input.value;
|
|
|
|
|
input.value = Weave.Clients.localName;
|
|
|
|
|
},
|
|
|
|
|
|
2011-02-03 10:54:00 -08:00
|
|
|
|
openChange: function openChange(type, duringSetup) {
|
2010-08-02 16:37:56 -07:00
|
|
|
|
// Just re-show the dialog if it's already open
|
2011-05-19 18:08:07 -07:00
|
|
|
|
let openedDialog = Services.wm.getMostRecentWindow("Sync:" + type);
|
2010-08-02 16:37:56 -07:00
|
|
|
|
if (openedDialog != null) {
|
|
|
|
|
openedDialog.focus();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Open up the change dialog
|
|
|
|
|
let changeXUL = "chrome://browser/content/syncGenericChange.xul";
|
2011-01-24 12:48:36 -08:00
|
|
|
|
let changeOpt = "centerscreen,chrome,resizable=no";
|
2011-05-19 18:08:07 -07:00
|
|
|
|
Services.ww.activeWindow.openDialog(changeXUL, "", changeOpt,
|
|
|
|
|
type, duringSetup);
|
2010-08-02 16:37:56 -07:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
changePassword: function () {
|
2011-01-13 21:43:25 -08:00
|
|
|
|
if (Weave.Utils.ensureMPUnlocked())
|
|
|
|
|
this.openChange("ChangePassword");
|
2010-08-02 16:37:56 -07:00
|
|
|
|
},
|
|
|
|
|
|
2011-02-03 10:54:00 -08:00
|
|
|
|
resetPassphrase: function (duringSetup) {
|
2011-01-13 21:43:25 -08:00
|
|
|
|
if (Weave.Utils.ensureMPUnlocked())
|
2011-02-03 10:54:00 -08:00
|
|
|
|
this.openChange("ResetPassphrase", duringSetup);
|
2010-08-02 16:37:56 -07:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
updatePassphrase: function () {
|
2011-01-13 21:43:25 -08:00
|
|
|
|
if (Weave.Utils.ensureMPUnlocked())
|
|
|
|
|
this.openChange("UpdatePassphrase");
|
2010-08-02 16:37:56 -07:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
resetPassword: function () {
|
|
|
|
|
this._openLink(Weave.Service.pwResetURL);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
openToS: function () {
|
|
|
|
|
this._openLink(Weave.Svc.Prefs.get("termsURL"));
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
openPrivacyPolicy: function () {
|
|
|
|
|
this._openLink(Weave.Svc.Prefs.get("privacyURL"));
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// xxxmpc - fix domain before 1.3 final (bug 583652)
|
|
|
|
|
_baseURL: "http://www.mozilla.com/firefox/sync/",
|
|
|
|
|
|
|
|
|
|
openFirstClientFirstrun: function () {
|
|
|
|
|
let url = this._baseURL + "firstrun.html";
|
|
|
|
|
this._openLink(url);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
openAddedClientFirstrun: function () {
|
|
|
|
|
let url = this._baseURL + "secondrun.html";
|
|
|
|
|
this._openLink(url);
|
|
|
|
|
},
|
|
|
|
|
|
2010-09-07 18:37:46 -07:00
|
|
|
|
/**
|
|
|
|
|
* Prepare an invisible iframe with the passphrase backup document.
|
|
|
|
|
* Used by both the print and saving methods.
|
|
|
|
|
*
|
|
|
|
|
* @param elid : ID of the form element containing the passphrase.
|
|
|
|
|
* @param callback : Function called once the iframe has loaded.
|
|
|
|
|
*/
|
|
|
|
|
_preparePPiframe: function(elid, callback) {
|
|
|
|
|
let pp = document.getElementById(elid).value;
|
|
|
|
|
|
|
|
|
|
// Create an invisible iframe whose contents we can print.
|
|
|
|
|
let iframe = document.createElement("iframe");
|
|
|
|
|
iframe.setAttribute("src", "chrome://browser/content/syncKey.xhtml");
|
|
|
|
|
iframe.collapsed = true;
|
|
|
|
|
document.documentElement.appendChild(iframe);
|
|
|
|
|
iframe.contentWindow.addEventListener("load", function() {
|
|
|
|
|
iframe.contentWindow.removeEventListener("load", arguments.callee, false);
|
|
|
|
|
|
|
|
|
|
// Insert the Sync Key into the page.
|
|
|
|
|
let el = iframe.contentDocument.getElementById("synckey");
|
|
|
|
|
el.firstChild.nodeValue = pp;
|
|
|
|
|
|
2010-09-17 07:58:11 -07:00
|
|
|
|
// Insert the TOS and Privacy Policy URLs into the page.
|
|
|
|
|
let termsURL = Weave.Svc.Prefs.get("termsURL");
|
|
|
|
|
el = iframe.contentDocument.getElementById("tosLink");
|
|
|
|
|
el.setAttribute("href", termsURL);
|
|
|
|
|
el.firstChild.nodeValue = termsURL;
|
|
|
|
|
|
|
|
|
|
let privacyURL = Weave.Svc.Prefs.get("privacyURL");
|
|
|
|
|
el = iframe.contentDocument.getElementById("ppLink");
|
|
|
|
|
el.setAttribute("href", privacyURL);
|
|
|
|
|
el.firstChild.nodeValue = privacyURL;
|
|
|
|
|
|
2010-09-07 18:37:46 -07:00
|
|
|
|
callback(iframe);
|
|
|
|
|
}, false);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Print passphrase backup document.
|
|
|
|
|
*
|
|
|
|
|
* @param elid : ID of the form element containing the passphrase.
|
|
|
|
|
*/
|
|
|
|
|
passphrasePrint: function(elid) {
|
|
|
|
|
this._preparePPiframe(elid, function(iframe) {
|
|
|
|
|
let webBrowserPrint = iframe.contentWindow
|
|
|
|
|
.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
|
.getInterface(Ci.nsIWebBrowserPrint);
|
|
|
|
|
let printSettings = PrintUtils.getPrintSettings();
|
|
|
|
|
|
|
|
|
|
// Display no header/footer decoration except for the date.
|
|
|
|
|
printSettings.headerStrLeft
|
|
|
|
|
= printSettings.headerStrCenter
|
|
|
|
|
= printSettings.headerStrRight
|
|
|
|
|
= printSettings.footerStrLeft
|
|
|
|
|
= printSettings.footerStrCenter = "";
|
|
|
|
|
printSettings.footerStrRight = "&D";
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
webBrowserPrint.print(printSettings, null);
|
|
|
|
|
} catch (ex) {
|
|
|
|
|
// print()'s return codes are expressed as exceptions. Ignore.
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Save passphrase backup document to disk as HTML file.
|
|
|
|
|
*
|
|
|
|
|
* @param elid : ID of the form element containing the passphrase.
|
|
|
|
|
*/
|
|
|
|
|
passphraseSave: function(elid) {
|
2011-08-19 14:35:29 -07:00
|
|
|
|
let dialogTitle = this.bundle.GetStringFromName("save.recoverykey.title");
|
|
|
|
|
let defaultSaveName = this.bundle.GetStringFromName("save.recoverykey.defaultfilename");
|
2010-09-07 18:37:46 -07:00
|
|
|
|
this._preparePPiframe(elid, function(iframe) {
|
|
|
|
|
let filepicker = Cc["@mozilla.org/filepicker;1"]
|
|
|
|
|
.createInstance(Ci.nsIFilePicker);
|
|
|
|
|
filepicker.init(window, dialogTitle, Ci.nsIFilePicker.modeSave);
|
|
|
|
|
filepicker.appendFilters(Ci.nsIFilePicker.filterHTML);
|
2011-05-11 17:57:03 -07:00
|
|
|
|
filepicker.defaultString = defaultSaveName;
|
2010-09-07 18:37:46 -07:00
|
|
|
|
let rv = filepicker.show();
|
|
|
|
|
if (rv == Ci.nsIFilePicker.returnOK
|
|
|
|
|
|| rv == Ci.nsIFilePicker.returnReplace) {
|
|
|
|
|
let stream = Cc["@mozilla.org/network/file-output-stream;1"]
|
|
|
|
|
.createInstance(Ci.nsIFileOutputStream);
|
|
|
|
|
stream.init(filepicker.file, -1, -1, 0);
|
|
|
|
|
|
|
|
|
|
let serializer = new XMLSerializer();
|
|
|
|
|
let output = serializer.serializeToString(iframe.contentDocument);
|
2010-09-17 07:58:11 -07:00
|
|
|
|
output = output.replace(/<!DOCTYPE (.|\n)*?]>/,
|
|
|
|
|
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" ' +
|
|
|
|
|
'"DTD/xhtml1-strict.dtd">');
|
2010-09-07 18:37:46 -07:00
|
|
|
|
output = Weave.Utils.encodeUTF8(output);
|
|
|
|
|
stream.write(output, output.length);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
2010-08-02 16:37:56 -07:00
|
|
|
|
/**
|
2010-09-07 18:37:46 -07:00
|
|
|
|
* validatePassword
|
2010-08-02 16:37:56 -07:00
|
|
|
|
*
|
|
|
|
|
* @param el1 : the first textbox element in the form
|
|
|
|
|
* @param el2 : the second textbox element, if omitted it's an update form
|
|
|
|
|
*
|
|
|
|
|
* returns [valid, errorString]
|
|
|
|
|
*/
|
|
|
|
|
validatePassword: function (el1, el2) {
|
|
|
|
|
let valid = false;
|
|
|
|
|
let val1 = el1.value;
|
|
|
|
|
let val2 = el2 ? el2.value : "";
|
|
|
|
|
let error = "";
|
|
|
|
|
|
2010-09-07 18:37:46 -07:00
|
|
|
|
if (!el2)
|
|
|
|
|
valid = val1.length >= Weave.MIN_PASS_LENGTH;
|
|
|
|
|
else if (val1 && val1 == Weave.Service.username)
|
|
|
|
|
error = "change.password.pwSameAsUsername";
|
2010-09-15 06:55:04 -07:00
|
|
|
|
else if (val1 && val1 == Weave.Service.account)
|
|
|
|
|
error = "change.password.pwSameAsEmail";
|
2010-09-07 18:37:46 -07:00
|
|
|
|
else if (val1 && val1 == Weave.Service.password)
|
|
|
|
|
error = "change.password.pwSameAsPassword";
|
|
|
|
|
else if (val1 && val1 == Weave.Service.passphrase)
|
2011-08-19 14:35:29 -07:00
|
|
|
|
error = "change.password.pwSameAsRecoveryKey";
|
2010-09-07 18:37:46 -07:00
|
|
|
|
else if (val1 && val2) {
|
|
|
|
|
if (val1 == val2 && val1.length >= Weave.MIN_PASS_LENGTH)
|
|
|
|
|
valid = true;
|
|
|
|
|
else if (val1.length < Weave.MIN_PASS_LENGTH)
|
|
|
|
|
error = "change.password.tooShort";
|
|
|
|
|
else if (val1 != val2)
|
|
|
|
|
error = "change.password.mismatch";
|
2010-08-02 16:37:56 -07:00
|
|
|
|
}
|
|
|
|
|
let errorString = error ? Weave.Utils.getErrorString(error) : "";
|
2010-09-07 18:37:46 -07:00
|
|
|
|
return [valid, errorString];
|
2010-08-02 16:37:56 -07:00
|
|
|
|
}
|
2010-11-30 20:39:32 -08:00
|
|
|
|
};
|