Bug 1473470 - Part 2 - Inform user about synced logins if Sync is used. r=JanH
authorPetru Lingurar <petru.lingurar@softvision.ro>
Tue, 15 Jan 2019 11:01:08 +0200
changeset 513887 ae52a3250ebf124caed547e09671af3f29928d20
parent 513886 ffef7bf31900e6bd360017e414338b454bfffa41
child 513888 5d0fef351a29306c1e46fbc70681ff1791cf6973
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersJanH
bugs1473470
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1473470 - Part 2 - Inform user about synced logins if Sync is used. r=JanH Summary: The reason for this ticket was that it was not immediately obvious for Sync users that deleting logins on this device may affect all logins stored in user's Sync account. So it was possible that users could unintentionally loose all their login data. While we should still offer the option to remove login data, even to Sync users, we will explicitly inform them that deleting logins can affect all their synced logins. Also refactored the code to minimize duplicated code. Depends on D16026 Reviewers: JanH, #geckoview-reviewers Reviewed By: JanH Subscribers: reviewbot, flod Bug #: 1473470 Differential Revision: https://phabricator.services.mozilla.com/D16027
mobile/android/chrome/content/aboutLogins.js
mobile/android/locales/en-US/chrome/aboutLogins.properties
--- a/mobile/android/chrome/content/aboutLogins.js
+++ b/mobile/android/chrome/content/aboutLogins.js
@@ -1,15 +1,16 @@
 /* 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/. */
 
 ChromeUtils.import("resource://services-common/utils.js"); /* global: CommonUtils */
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
+ChromeUtils.import("resource://gre/modules/Accounts.jsm");
 
 XPCOMUtils.defineLazyGetter(window, "gChromeWin", () =>
   window.docShell.rootTreeItem.domWindow
     .QueryInterface(Ci.nsIDOMChromeWindow));
 
 ChromeUtils.defineModuleGetter(this, "EventDispatcher",
                                "resource://gre/modules/Messaging.jsm");
 ChromeUtils.defineModuleGetter(this, "Snackbars", "resource://gre/modules/Snackbars.jsm");
@@ -384,56 +385,61 @@ var Logins = {
           copyStringShowSnackbar(login.username, gStringBundle.GetStringFromName("loginsDetails.usernameCopied"));
           break;
         case 3:
           this._selectedLogin = login;
           this._showEditLoginDialog(login);
           history.pushState({ id: login.guid }, document.title);
           break;
         case 4:
-          let deleteLoginConfirmPrompt = new Prompt({
-            window: window,
-            message: gStringBundle.GetStringFromName("loginsDialog.confirmDelete"),
-            buttons: [
-              gStringBundle.GetStringFromName("loginsDialog.confirm"),
-              gStringBundle.GetStringFromName("loginsDialog.cancel") ],
-          });
-          deleteLoginConfirmPrompt.show((data) => {
-            switch (data.button) {
-              case 0:
-                // Corresponds to "confirm" button.
-                Services.logins.removeLogin(login);
+          Accounts.getFirefoxAccount().then(user => {
+             const promptMessage = user ? gStringBundle.GetStringFromName("loginsDialog.confirmDeleteForFxaUser")
+                                        : gStringBundle.GetStringFromName("loginsDialog.confirmDelete");
+             const confirmationMessage = gStringBundle.GetStringFromName("loginsDetails.deleted");
 
-                // Show a snackbar to notify the login record has been deleted.
-                Snackbars.show(gStringBundle.GetStringFromName("loginsDetails.deleted"), Snackbars.LENGTH_LONG);
-            }
+             this._showConfirmationPrompt(promptMessage,
+                                          confirmationMessage,
+                                          () => Services.logins.removeLogin(login));
           });
           break;
         case 5:
-          let deleteAllLoginsConfirmPrompt = new Prompt({
-            window: window,
-            message: gStringBundle.GetStringFromName("loginsDialog.confirmDeleteAll"),
-            buttons: [
-              gStringBundle.GetStringFromName("loginsDialog.confirm"),
-              gStringBundle.GetStringFromName("loginsDialog.cancel") ],
+          Accounts.getFirefoxAccount().then(user => {
+             const promptMessage = user ? gStringBundle.GetStringFromName("loginsDialog.confirmDeleteAllForFxaUser")
+                                        : gStringBundle.GetStringFromName("loginsDialog.confirmDeleteAll");
+             const confirmationMessage = gStringBundle.GetStringFromName("loginsDetails.deletedAll");
+
+             this._showConfirmationPrompt(promptMessage,
+                                          confirmationMessage,
+                                          () => Services.logins.removeAllLogins());
           });
-          deleteAllLoginsConfirmPrompt.show((data) => {
-            switch (data.button) {
-              case 0:
-                // Corresponds to "confirm" button.
-                Services.logins.removeAllLogins();
-
-                // Show a snackbar to notify that all logins records have been deleted.
-                Snackbars.show(gStringBundle.GetStringFromName("loginsDetails.deletedAll"), Snackbars.LENGTH_LONG);
-            }
-          });
+          break;
       }
     });
   },
 
+   _showConfirmationPrompt: function(promptMessage, confirmationMessage, actionToPerform) {
+     new Prompt({
+         window: window,
+         message: promptMessage,
+         buttons: [
+           // Use default, generic values
+           gStringBundle.GetStringFromName("loginsDialog.confirm"),
+           gStringBundle.GetStringFromName("loginsDialog.cancel") ],
+       }).show((data) => {
+         switch (data.button) {
+           case 0:
+             // Corresponds to "confirm" button.
+
+             actionToPerform();
+
+             Snackbars.show(confirmationMessage, Snackbars.LENGTH_LONG);
+         }
+       });
+   },
+
   _loadFavicon: function(aImg, aHostname) {
     // Load favicon from cache.
     EventDispatcher.instance.sendRequestForResult({
       type: "Favicon:Request",
       url: aHostname,
       skipNetwork: true,
     }).then(function(faviconUrl) {
       aImg.style.backgroundImage = "url('" + faviconUrl + "')";
--- a/mobile/android/locales/en-US/chrome/aboutLogins.properties
+++ b/mobile/android/locales/en-US/chrome/aboutLogins.properties
@@ -5,17 +5,19 @@
 loginsMenu.showPassword=Show password
 loginsMenu.copyPassword=Copy password
 loginsMenu.copyUsername=Copy username
 loginsMenu.editLogin=Edit login
 loginsMenu.delete=Delete
 loginsMenu.deleteAll=Delete All
 
 loginsDialog.confirmDelete=Delete this login?
+loginsDialog.confirmDeleteForFxaUser=Delete this login?\n\nThis can affect synced logins.
 loginsDialog.confirmDeleteAll=Delete all logins?
+loginsDialog.confirmDeleteAllForFxaUser=Delete all logins?\n\nThis can affect synced logins.
 loginsDialog.copy=Copy
 loginsDialog.confirm=OK
 loginsDialog.cancel=Cancel
 
 editLogin.fallbackTitle=Edit Login
 editLogin.saved1=Saved login
 editLogin.couldNotSave=Changes could not be saved