From c3cc3b6407e55c52ad302df9baa9c1b1211c95f5 Mon Sep 17 00:00:00 2001 From: Wes Kocher Date: Thu, 26 Jan 2017 11:16:12 -0800 Subject: [PATCH] Backed out 13 changesets (bug 1296767) for xpcshell failures a=backout CLOSED TREE Backed out changeset 41ed77788333 (bug 1296767) Backed out changeset 1c0c9289b532 (bug 1296767) Backed out changeset 50294db1d871 (bug 1296767) Backed out changeset 26c065f79c54 (bug 1296767) Backed out changeset 0362a78d6978 (bug 1296767) Backed out changeset 4e71cf94e4ee (bug 1296767) Backed out changeset f6f59447d22a (bug 1296767) Backed out changeset 6c9b792cc296 (bug 1296767) Backed out changeset 46a52b10a868 (bug 1296767) Backed out changeset 5d70d87d2a8f (bug 1296767) Backed out changeset 8219686be6a2 (bug 1296767) Backed out changeset 0a989b0cea67 (bug 1296767) Backed out changeset 9f59a0b75c1f (bug 1296767) MozReview-Commit-ID: 2XBNsd8JrZL --HG-- extra : amend_source : 1afafaa8127fcebac31ce1d7743dc16872fa0522 --- b2g/installer/package-manifest.in | 1 + .../content/aboutaccounts/aboutaccounts.js | 23 +- .../content/aboutaccounts/aboutaccounts.xhtml | 4 + browser/base/content/browser-fxaccounts.js | 77 +- browser/base/content/browser-menubar.inc | 2 +- browser/base/content/browser-syncui.js | 88 +- browser/base/content/sync/addDevice.js | 157 +++ browser/base/content/sync/addDevice.xul | 129 ++ browser/base/content/sync/customize.css | 28 + browser/base/content/sync/customize.js | 25 + browser/base/content/sync/customize.xul | 67 ++ browser/base/content/sync/genericChange.js | 226 ++++ browser/base/content/sync/genericChange.xul | 123 ++ browser/base/content/sync/key.xhtml | 54 + browser/base/content/sync/setup.js | 1057 +++++++++++++++++ browser/base/content/sync/setup.xul | 490 ++++++++ browser/base/content/sync/utils.js | 229 ++++ browser/base/content/test/general/browser.ini | 1 + .../test/general/browser_fxa_migrate.js | 18 + .../test/general/browser_fxaccounts.js | 20 +- browser/base/jar.mn | 11 + .../customizableui/content/panelUI.inc.xul | 6 +- .../components/preferences/in-content/sync.js | 380 ++++-- .../preferences/in-content/sync.xul | 134 +++ .../syncedtabs/SyncedTabsDeckComponent.js | 2 +- .../xpcshell/test_SyncedTabsDeckComponent.js | 6 +- browser/components/uitour/test/browser.ini | 2 +- browser/components/uitour/test/browser_fxa.js | 4 +- browser/installer/package-manifest.in | 1 + .../en-US/chrome/browser/aboutAccounts.dtd | 1 + .../en-US/chrome/browser/accounts.properties | 8 + .../preferences/preferences.properties | 4 + .../en-US/chrome/browser/preferences/sync.dtd | 31 + .../en-US/chrome/browser/syncCustomize.dtd | 27 + .../browser/syncGenericChange.properties | 37 + .../locales/en-US/chrome/browser/syncKey.dtd | 18 + .../en-US/chrome/browser/syncQuota.dtd | 8 + .../en-US/chrome/browser/syncQuota.properties | 42 + .../en-US/chrome/browser/syncSetup.dtd | 114 ++ .../en-US/chrome/browser/syncSetup.properties | 45 + browser/locales/jar.mn | 6 + browser/themes/linux/jar.mn | 3 + .../themes/linux/preferences/preferences.css | 13 + browser/themes/linux/syncCommon.css | 49 + browser/themes/linux/syncQuota.css | 26 + browser/themes/linux/syncSetup.css | 133 +++ browser/themes/osx/jar.mn | 3 + .../themes/osx/preferences/preferences.css | 13 + browser/themes/osx/syncCommon.css | 55 + browser/themes/osx/syncQuota.css | 26 + browser/themes/osx/syncSetup.css | 139 +++ .../shared/customizableui/panelUI.inc.css | 6 + .../shared/incontentprefs/preferences.inc.css | 9 +- browser/themes/windows/jar.mn | 3 + .../windows/preferences/preferences.css | 17 + browser/themes/windows/syncCommon.css | 55 + browser/themes/windows/syncQuota.css | 26 + browser/themes/windows/syncSetup.css | 145 +++ mobile/android/installer/package-manifest.in | 1 + services/common/tests/unit/head_helpers.js | 13 + services/crypto/component/moz.build | 21 + services/crypto/component/nsISyncJPAKE.idl | 103 ++ services/crypto/component/nsSyncJPAKE.cpp | 484 ++++++++ services/crypto/component/nsSyncJPAKE.h | 38 + .../crypto/component/tests/unit/test_jpake.js | 289 +++++ .../crypto/component/tests/unit/xpcshell.ini | 5 + services/crypto/moz.build | 2 + services/fxaccounts/FxAccountsWebChannel.jsm | 28 +- services/fxaccounts/tests/xpcshell/head.js | 1 - .../tests/xpcshell/test_accounts.js | 1 + .../test_accounts_device_registration.js | 1 + .../tests/xpcshell/test_loginmgr_storage.js | 1 + .../tests/xpcshell/test_oauth_grant_client.js | 1 + .../tests/xpcshell/test_push_service.js | 1 + .../tests/xpcshell/test_storage_manager.js | 1 + .../tests/xpcshell/test_web_channel.js | 18 + services/sync/Weave.js | 31 +- services/sync/locales/en-US/sync.properties | 11 + services/sync/modules-testing/utils.js | 133 ++- services/sync/modules/FxaMigrator.jsm | 99 ++ services/sync/modules/browserid_identity.js | 174 +-- services/sync/modules/constants.js | 15 + services/sync/modules/engines.js | 1 + services/sync/modules/identity.js | 604 ++++++++++ services/sync/modules/jpakeclient.js | 773 ++++++++++++ services/sync/modules/main.js | 1 + services/sync/modules/policies.js | 13 +- services/sync/modules/rest.js | 7 +- services/sync/modules/service.js | 346 +++++- services/sync/modules/stages/cluster.js | 113 ++ services/sync/modules/status.js | 8 +- services/sync/modules/userapi.js | 219 ++++ services/sync/modules/util.js | 6 + services/sync/moz.build | 5 + services/sync/services-sync.js | 17 + services/sync/tests/unit/head_http_server.js | 5 - .../sync/tests/unit/test_bookmark_duping.js | 1 + .../tests/unit/test_browserid_identity.js | 5 + .../sync/tests/unit/test_clients_engine.js | 2 +- .../tests/unit/test_collections_recovery.js | 2 +- services/sync/tests/unit/test_corrupt_keys.js | 2 +- .../sync/tests/unit/test_errorhandler_1.js | 89 +- .../sync/tests/unit/test_errorhandler_2.js | 36 +- .../sync/tests/unit/test_errorhandler_eol.js | 6 +- ...test_errorhandler_sync_checkServerError.js | 14 +- .../sync/tests/unit/test_fxa_migration.js | 98 ++ .../sync/tests/unit/test_fxa_startOver.js | 64 + .../sync/tests/unit/test_history_engine.js | 1 + services/sync/tests/unit/test_hmac_error.js | 9 + .../sync/tests/unit/test_identity_manager.js | 284 +++++ .../sync/tests/unit/test_interval_triggers.js | 10 +- services/sync/tests/unit/test_jpakeclient.js | 562 +++++++++ services/sync/tests/unit/test_keys.js | 17 +- services/sync/tests/unit/test_load_modules.js | 4 + .../sync/tests/unit/test_node_reassignment.js | 113 +- services/sync/tests/unit/test_records_wbo.js | 1 + services/sync/tests/unit/test_resource.js | 17 +- .../sync/tests/unit/test_resource_async.js | 11 +- .../unit/test_sendcredentials_controller.js | 102 ++ .../tests/unit/test_service_attributes.js | 30 + .../tests/unit/test_service_changePassword.js | 80 ++ .../tests/unit/test_service_checkAccount.js | 41 + .../sync/tests/unit/test_service_cluster.js | 63 +- .../tests/unit/test_service_createAccount.js | 75 ++ .../tests/unit/test_service_detect_upgrade.js | 32 +- .../tests/unit/test_service_getStorageInfo.js | 22 +- .../sync/tests/unit/test_service_login.js | 63 +- .../tests/unit/test_service_passwordUTF8.js | 94 ++ .../tests/unit/test_service_persistLogin.js | 46 + .../tests/unit/test_service_set_serverURL.js | 13 + .../sync/tests/unit/test_service_startOver.js | 8 +- .../unit/test_service_sync_remoteSetup.js | 49 +- .../tests/unit/test_service_verifyLogin.js | 48 +- .../tests/unit/test_service_wipeClient.js | 29 +- .../tests/unit/test_service_wipeServer.js | 14 +- services/sync/tests/unit/test_status.js | 1 + .../sync/tests/unit/test_status_checkSetup.js | 22 +- services/sync/tests/unit/test_syncedtabs.js | 2 + .../sync/tests/unit/test_syncengine_sync.js | 37 +- .../sync/tests/unit/test_syncscheduler.js | 134 ++- .../tests/unit/test_syncstoragerequest.js | 9 +- services/sync/tests/unit/test_tab_engine.js | 1 + services/sync/tests/unit/test_telemetry.js | 11 +- .../tests/unit/test_upgrade_old_sync_key.js | 49 + .../sync/tests/unit/test_utils_passphrase.js | 4 + services/sync/tests/unit/xpcshell.ini | 19 + .../tps/extensions/tps/resource/auth/sync.jsm | 88 ++ .../sync/tps/extensions/tps/resource/tps.jsm | 27 +- .../telemetry/TelemetryEnvironment.jsm | 1 + tools/lint/eslint/modules.json | 7 +- 150 files changed, 10045 insertions(+), 541 deletions(-) create mode 100644 browser/base/content/sync/addDevice.js create mode 100644 browser/base/content/sync/addDevice.xul create mode 100644 browser/base/content/sync/customize.css create mode 100644 browser/base/content/sync/customize.js create mode 100644 browser/base/content/sync/customize.xul create mode 100644 browser/base/content/sync/genericChange.js create mode 100644 browser/base/content/sync/genericChange.xul create mode 100644 browser/base/content/sync/key.xhtml create mode 100644 browser/base/content/sync/setup.js create mode 100644 browser/base/content/sync/setup.xul create mode 100644 browser/base/content/sync/utils.js create mode 100644 browser/base/content/test/general/browser_fxa_migrate.js create mode 100644 browser/locales/en-US/chrome/browser/syncCustomize.dtd create mode 100644 browser/locales/en-US/chrome/browser/syncGenericChange.properties create mode 100644 browser/locales/en-US/chrome/browser/syncKey.dtd create mode 100644 browser/locales/en-US/chrome/browser/syncQuota.dtd create mode 100644 browser/locales/en-US/chrome/browser/syncQuota.properties create mode 100644 browser/locales/en-US/chrome/browser/syncSetup.dtd create mode 100644 browser/themes/linux/syncCommon.css create mode 100644 browser/themes/linux/syncQuota.css create mode 100644 browser/themes/linux/syncSetup.css create mode 100644 browser/themes/osx/syncCommon.css create mode 100644 browser/themes/osx/syncQuota.css create mode 100644 browser/themes/osx/syncSetup.css create mode 100644 browser/themes/windows/syncCommon.css create mode 100644 browser/themes/windows/syncQuota.css create mode 100644 browser/themes/windows/syncSetup.css create mode 100644 services/crypto/component/moz.build create mode 100644 services/crypto/component/nsISyncJPAKE.idl create mode 100644 services/crypto/component/nsSyncJPAKE.cpp create mode 100644 services/crypto/component/nsSyncJPAKE.h create mode 100644 services/crypto/component/tests/unit/test_jpake.js create mode 100644 services/crypto/component/tests/unit/xpcshell.ini create mode 100644 services/sync/modules/FxaMigrator.jsm create mode 100644 services/sync/modules/identity.js create mode 100644 services/sync/modules/jpakeclient.js create mode 100644 services/sync/modules/stages/cluster.js create mode 100644 services/sync/modules/userapi.js create mode 100644 services/sync/tests/unit/test_fxa_migration.js create mode 100644 services/sync/tests/unit/test_fxa_startOver.js create mode 100644 services/sync/tests/unit/test_identity_manager.js create mode 100644 services/sync/tests/unit/test_jpakeclient.js create mode 100644 services/sync/tests/unit/test_sendcredentials_controller.js create mode 100644 services/sync/tests/unit/test_service_changePassword.js create mode 100644 services/sync/tests/unit/test_service_checkAccount.js create mode 100644 services/sync/tests/unit/test_service_createAccount.js create mode 100644 services/sync/tests/unit/test_service_passwordUTF8.js create mode 100644 services/sync/tests/unit/test_service_persistLogin.js create mode 100644 services/sync/tests/unit/test_service_set_serverURL.js create mode 100644 services/sync/tests/unit/test_upgrade_old_sync_key.js create mode 100644 services/sync/tps/extensions/tps/resource/auth/sync.jsm diff --git a/b2g/installer/package-manifest.in b/b2g/installer/package-manifest.in index f4908447e768..38ce27182aa4 100644 --- a/b2g/installer/package-manifest.in +++ b/b2g/installer/package-manifest.in @@ -268,6 +268,7 @@ @RESPATH@/components/satchel.xpt @RESPATH@/components/saxparser.xpt @RESPATH@/components/sessionstore.xpt +@RESPATH@/components/services-crypto-component.xpt @RESPATH@/components/captivedetect.xpt @RESPATH@/components/shellservice.xpt @RESPATH@/components/shistory.xpt diff --git a/browser/base/content/aboutaccounts/aboutaccounts.js b/browser/base/content/aboutaccounts/aboutaccounts.js index 9c6f7458cdd9..acfaa1f8a0cc 100644 --- a/browser/base/content/aboutaccounts/aboutaccounts.js +++ b/browser/base/content/aboutaccounts/aboutaccounts.js @@ -16,6 +16,7 @@ Cu.import("resource://gre/modules/FxAccountsCommon.js", fxAccountsCommon); Cu.import("resource://services-sync/util.js"); const PREF_LAST_FXA_USER = "identity.fxaccounts.lastSignedInUserHash"; +const PREF_SYNC_SHOW_CUSTOMIZATION = "services.sync-setup.ui.showCustomizationDialog"; const ACTION_URL_PARAM = "action"; @@ -196,8 +197,9 @@ var wrapper = { onLogin(accountData) { log("Received: 'login'. Data:" + JSON.stringify(accountData)); - // We don't act on customizeSync anymore, it used to open a dialog inside - // the browser to selecte the engines to sync but we do it on the web now. + if (accountData.customizeSync) { + Services.prefs.setBoolPref(PREF_SYNC_SHOW_CUSTOMIZATION, true); + } delete accountData.customizeSync; // sessionTokenContext is erroneously sent by the content server. // https://github.com/mozilla/fxa-content-server/issues/2766 @@ -304,6 +306,18 @@ var wrapper = { // Button onclick handlers +function handleOldSync() { + let chromeWin = window + .QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIWebNavigation) + .QueryInterface(Ci.nsIDocShellTreeItem) + .rootTreeItem + .QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIDOMWindow) + .QueryInterface(Ci.nsIDOMChromeWindow); + let url = Services.urlFormatter.formatURLPref("app.support.baseURL") + "old-sync"; + chromeWin.switchToTabHavingURI(url, true); +} function getStarted() { show("remote"); @@ -491,7 +505,10 @@ document.addEventListener("DOMContentLoaded", function() { var buttonRetry = document.getElementById("buttonRetry"); buttonRetry.addEventListener("click", retry); - var buttonOpenPrefs = document.getElementById("buttonOpenPrefs"); + var oldsync = document.getElementById("oldsync"); + oldsync.addEventListener("click", handleOldSync); + + var buttonOpenPrefs = document.getElementById("buttonOpenPrefs") buttonOpenPrefs.addEventListener("click", openPrefs); }, {capture: true, once: true}); diff --git a/browser/base/content/aboutaccounts/aboutaccounts.xhtml b/browser/base/content/aboutaccounts/aboutaccounts.xhtml index dc5872abc555..e188aa49668e 100644 --- a/browser/base/content/aboutaccounts/aboutaccounts.xhtml +++ b/browser/base/content/aboutaccounts/aboutaccounts.xhtml @@ -63,6 +63,10 @@
+ + diff --git a/browser/base/content/browser-fxaccounts.js b/browser/base/content/browser-fxaccounts.js index 9dc78779ee6f..16d256c2d80c 100644 --- a/browser/base/content/browser-fxaccounts.js +++ b/browser/base/content/browser-fxaccounts.js @@ -4,6 +4,8 @@ var gFxAccounts = { + SYNC_MIGRATION_NOTIFICATION_TITLE: "fxa-migration", + _initialized: false, _inCustomizationMode: false, @@ -23,6 +25,7 @@ var gFxAccounts = { "weave:service:setup-complete", "weave:service:sync:error", "weave:ui:login:error", + "fxa-migration:state-changed", this.FxAccountsCommon.ONLOGIN_NOTIFICATION, this.FxAccountsCommon.ONLOGOUT_NOTIFICATION, this.FxAccountsCommon.ON_PROFILE_CHANGE_NOTIFICATION, @@ -140,6 +143,9 @@ var gFxAccounts = { observe(subject, topic, data) { switch (topic) { + case "fxa-migration:state-changed": + this.onMigrationStateChanged(data, subject); + break; case this.FxAccountsCommon.ONPROFILE_IMAGE_CHANGE_NOTIFICATION: this.updateUI(); break; @@ -149,18 +155,78 @@ var gFxAccounts = { } }, - handleEvent(event) { - this._inCustomizationMode = event.type == "customizationstarting"; - this.updateUI(); + onMigrationStateChanged() { + // Since we nuked most of the migration code, this notification will fire + // once after legacy Sync has been disconnected (and should never fire + // again) + let nb = window.document.getElementById("global-notificationbox"); + + let msg = this.strings.GetStringFromName("autoDisconnectDescription") + let signInLabel = this.strings.GetStringFromName("autoDisconnectSignIn.label"); + let signInAccessKey = this.strings.GetStringFromName("autoDisconnectSignIn.accessKey"); + let learnMoreLink = this.fxaMigrator.learnMoreLink; + + let buttons = [ + { + label: signInLabel, + accessKey: signInAccessKey, + callback: () => { + this.openPreferences(); + } + } + ]; + + let fragment = document.createDocumentFragment(); + let msgNode = document.createTextNode(msg); + fragment.appendChild(msgNode); + if (learnMoreLink) { + let link = document.createElement("label"); + link.className = "text-link"; + link.setAttribute("value", learnMoreLink.text); + link.href = learnMoreLink.href; + fragment.appendChild(link); + } + + nb.appendNotification(fragment, + this.SYNC_MIGRATION_NOTIFICATION_TITLE, + undefined, + nb.PRIORITY_WARNING_LOW, + buttons); + + // ensure the hamburger menu reflects the newly disconnected state. + this.updateAppMenuItem(); + }, + + handleEvent(event) { + this._inCustomizationMode = event.type == "customizationstarting"; + this.updateAppMenuItem(); }, - // Note that updateUI() returns a Promise that's only used by tests. updateUI() { + // It's possible someone signed in to FxA after seeing our notification + // about "Legacy Sync migration" (which now is actually "Legacy Sync + // auto-disconnect") so kill that notification if it still exists. + let nb = window.document.getElementById("global-notificationbox"); + let n = nb.getNotificationWithValue(this.SYNC_MIGRATION_NOTIFICATION_TITLE); + if (n) { + nb.removeNotification(n, true); + } + + this.updateAppMenuItem(); + }, + + // Note that updateAppMenuItem() returns a Promise that's only used by tests. + updateAppMenuItem() { let profileInfoEnabled = false; try { profileInfoEnabled = Services.prefs.getBoolPref("identity.fxaccounts.profile_image.enabled"); } catch (e) { } + // Bail out if FxA is disabled. + if (!this.weave.fxAccountsEnabled) { + return Promise.resolve(); + } + this.panelUIFooter.hidden = false; // Make sure the button is disabled in customization mode. @@ -411,5 +477,8 @@ XPCOMUtils.defineLazyGetter(gFxAccounts, "FxAccountsCommon", function() { return Cu.import("resource://gre/modules/FxAccountsCommon.js", {}); }); +XPCOMUtils.defineLazyModuleGetter(gFxAccounts, "fxaMigrator", + "resource://services-sync/FxaMigrator.jsm"); + XPCOMUtils.defineLazyModuleGetter(this, "EnsureFxAccountsWebChannel", "resource://gre/modules/FxAccountsWebChannel.jsm"); diff --git a/browser/base/content/browser-menubar.inc b/browser/base/content/browser-menubar.inc index 9d2c323976d4..2a92de58fb08 100644 --- a/browser/base/content/browser-menubar.inc +++ b/browser/base/content/browser-menubar.inc @@ -496,7 +496,7 @@ label="&syncSignIn.label;" accesskey="&syncSignIn.accesskey;" observes="sync-setup-state" - oncommand="gSyncUI.openPrefs('menubar')"/> + oncommand="gSyncUI.openSetup(null, 'menubar')"/> { - // We want to treat "account needs verification" as "needs setup". - return !(user && user.verified); - }); + // If Sync is configured for FxAccounts then we do that promise-dance. + if (this.weaveService.fxAccountsEnabled) { + return fxAccounts.getSignedInUser().then(user => { + // We want to treat "account needs verification" as "needs setup". + return !(user && user.verified); + }); + } + // We are using legacy sync - check that. + let firstSync = ""; + try { + firstSync = Services.prefs.getCharPref("services.sync.firstSync"); + } catch (e) { } + + return Promise.resolve(Weave.Status.checkSetup() == Weave.CLIENT_NOT_CONFIGURED || + firstSync == "notReady"); }, // Returns a promise that resolves with true if the user currently signed in // to Sync needs to be verified, false otherwise. _needsVerification() { - return fxAccounts.getSignedInUser().then(user => { - // If there is no user, they can't be in a "needs verification" state. - if (!user) { - return false; - } - return !user.verified; - }); + // For callers who care about the distinction between "needs setup" and + // "needs verification" + if (this.weaveService.fxAccountsEnabled) { + return fxAccounts.getSignedInUser().then(user => { + // If there is no user, they can't be in a "needs verification" state. + if (!user) { + return false; + } + return !user.verified; + }); + } + + // Otherwise we are configured for legacy Sync, which has no verification + // concept. + return Promise.resolve(false); }, // Note that we don't show login errors in a notification bar here, but do @@ -248,7 +267,7 @@ var gSyncUI = { handleToolbarButton() { this._needsSetup().then(needsSetup => { if (needsSetup || this.loginFailed()) { - this.openPrefs(); + this.openSetup(); } else { this.doSync(); } @@ -258,12 +277,46 @@ var gSyncUI = { }, /** - * Open the Sync preferences. + * 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 * @param entryPoint * Indicates the entrypoint from where this method was called. */ - openPrefs(entryPoint = "syncbutton") { + + openSetup: function SUI_openSetup(wizardType, entryPoint = "syncbutton") { + if (this.weaveService.fxAccountsEnabled) { + this.openPrefs(entryPoint); + } else { + let win = Services.wm.getMostRecentWindow("Weave:AccountSetup"); + if (win) + win.focus(); + else { + window.openDialog("chrome://browser/content/sync/setup.xul", + "weaveSetup", "centerscreen,chrome,resizable=no", + wizardType); + } + } + }, + + // Open the legacy-sync device pairing UI. Note used for FxA Sync. + openAddDevice() { + if (!Weave.Utils.ensureMPUnlocked()) + return; + + let win = Services.wm.getMostRecentWindow("Sync:AddDevice"); + if (win) + win.focus(); + else + window.openDialog("chrome://browser/content/sync/addDevice.xul", + "syncAddDevice", "centerscreen,chrome,resizable=no"); + }, + + openPrefs(entryPoint) { openPreferences("paneSync", { urlParams: { entrypoint: entryPoint } }); }, @@ -321,10 +374,9 @@ var gSyncUI = { return; let email; - let user = yield fxAccounts.getSignedInUser(); - if (user) { - email = user.email; - } + try { + email = Services.prefs.getCharPref("services.sync.username"); + } catch (ex) {} let needsSetup = yield this._needsSetup(); let needsVerification = yield this._needsVerification(); diff --git a/browser/base/content/sync/addDevice.js b/browser/base/content/sync/addDevice.js new file mode 100644 index 000000000000..3710dacd4960 --- /dev/null +++ b/browser/base/content/sync/addDevice.js @@ -0,0 +1,157 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +var Ci = Components.interfaces; +var Cc = Components.classes; +var Cu = Components.utils; + +Cu.import("resource://services-sync/main.js"); +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); + +const PIN_PART_LENGTH = 4; + +const ADD_DEVICE_PAGE = 0; +const SYNC_KEY_PAGE = 1; +const DEVICE_CONNECTED_PAGE = 2; + +var gSyncAddDevice = { + + init: function init() { + this.pin1.setAttribute("maxlength", PIN_PART_LENGTH); + this.pin2.setAttribute("maxlength", PIN_PART_LENGTH); + this.pin3.setAttribute("maxlength", PIN_PART_LENGTH); + + this.nextFocusEl = {pin1: this.pin2, + pin2: this.pin3, + pin3: this.wizard.getButton("next")}; + + this.throbber = document.getElementById("pairDeviceThrobber"); + this.errorRow = document.getElementById("errorRow"); + + // Kick off a sync. That way the server will have the most recent data from + // this computer and it will show up immediately on the new device. + Weave.Service.scheduler.scheduleNextSync(0); + }, + + onPageShow: function onPageShow() { + this.wizard.getButton("back").hidden = true; + + switch (this.wizard.pageIndex) { + case ADD_DEVICE_PAGE: + this.onTextBoxInput(); + this.wizard.canRewind = false; + this.wizard.getButton("next").hidden = false; + this.pin1.focus(); + break; + case SYNC_KEY_PAGE: + this.wizard.canAdvance = false; + this.wizard.canRewind = true; + this.wizard.getButton("back").hidden = false; + this.wizard.getButton("next").hidden = true; + document.getElementById("weavePassphrase").value = + Weave.Utils.hyphenatePassphrase(Weave.Service.identity.syncKey); + break; + case DEVICE_CONNECTED_PAGE: + this.wizard.canAdvance = true; + this.wizard.canRewind = false; + this.wizard.getButton("cancel").hidden = true; + break; + } + }, + + onWizardAdvance: function onWizardAdvance() { + switch (this.wizard.pageIndex) { + case ADD_DEVICE_PAGE: + this.startTransfer(); + return false; + case DEVICE_CONNECTED_PAGE: + window.close(); + return false; + } + return true; + }, + + startTransfer: function startTransfer() { + this.errorRow.hidden = true; + // When onAbort is called, Weave may already be gone. + const JPAKE_ERROR_USERABORT = Weave.JPAKE_ERROR_USERABORT; + + let self = this; + let jpakeclient = this._jpakeclient = new Weave.JPAKEClient({ + onPaired: function onPaired() { + let credentials = {account: Weave.Service.identity.account, + password: Weave.Service.identity.basicPassword, + synckey: Weave.Service.identity.syncKey, + serverURL: Weave.Service.serverURL}; + jpakeclient.sendAndComplete(credentials); + }, + onComplete: function onComplete() { + delete self._jpakeclient; + self.wizard.pageIndex = DEVICE_CONNECTED_PAGE; + + // Schedule a Sync for soonish to fetch the data uploaded by the + // device with which we just paired. + Weave.Service.scheduler.scheduleNextSync(Weave.Service.scheduler.activeInterval); + }, + onAbort: function onAbort(error) { + delete self._jpakeclient; + + // Aborted by user, ignore. + if (error == JPAKE_ERROR_USERABORT) { + return; + } + + self.errorRow.hidden = false; + self.throbber.hidden = true; + self.pin1.value = self.pin2.value = self.pin3.value = ""; + self.pin1.disabled = self.pin2.disabled = self.pin3.disabled = false; + self.pin1.focus(); + } + }); + this.throbber.hidden = false; + this.pin1.disabled = this.pin2.disabled = this.pin3.disabled = true; + this.wizard.canAdvance = false; + + let pin = this.pin1.value + this.pin2.value + this.pin3.value; + let expectDelay = false; + jpakeclient.pairWithPIN(pin, expectDelay); + }, + + onWizardBack: function onWizardBack() { + if (this.wizard.pageIndex != SYNC_KEY_PAGE) + return true; + + this.wizard.pageIndex = ADD_DEVICE_PAGE; + return false; + }, + + onWizardCancel: function onWizardCancel() { + if (this._jpakeclient) { + this._jpakeclient.abort(); + delete this._jpakeclient; + } + return true; + }, + + onTextBoxInput: function onTextBoxInput(textbox) { + if (textbox && textbox.value.length == PIN_PART_LENGTH) + this.nextFocusEl[textbox.id].focus(); + + this.wizard.canAdvance = (this.pin1.value.length == PIN_PART_LENGTH + && this.pin2.value.length == PIN_PART_LENGTH + && this.pin3.value.length == PIN_PART_LENGTH); + }, + + goToSyncKeyPage: function goToSyncKeyPage() { + this.wizard.pageIndex = SYNC_KEY_PAGE; + } + +}; +// onWizardAdvance() and onPageShow() are run before init() so we'll set +// these up as lazy getters. +["wizard", "pin1", "pin2", "pin3"].forEach(function(id) { + XPCOMUtils.defineLazyGetter(gSyncAddDevice, id, function() { + return document.getElementById(id); + }); +}); diff --git a/browser/base/content/sync/addDevice.xul b/browser/base/content/sync/addDevice.xul new file mode 100644 index 000000000000..83c3b7b3c53b --- /dev/null +++ b/browser/base/content/sync/addDevice.xul @@ -0,0 +1,129 @@ + + + + + + + + + + + +%brandDTD; +%syncBrandDTD; +%syncSetupDTD; +]> + + +