Bug 896117 - Add enter and exit dialogs for guest mode. r=margaret
authorWes Johnston <wjohnston@mozilla.com>
Fri, 26 Jul 2013 09:14:04 -0700
changeset 140179 b51cb3254d1883bdf5797e76794dbdc063cf0cff
parent 140178 2e6def7eb4db466cd4dcb42fbbc590fa171d90a7
child 140180 bff7e921c95d46c7428db9e8e358ee5d8e492d8e
push id1945
push userryanvm@gmail.com
push dateSat, 27 Jul 2013 02:27:26 +0000
treeherderfx-team@4874fa438b1c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret
bugs896117
milestone25.0a1
Bug 896117 - Add enter and exit dialogs for guest mode. r=margaret
mobile/android/base/BrowserApp.java
mobile/android/base/Prompt.java
mobile/android/base/locales/en-US/android_strings.dtd
mobile/android/base/strings.xml.in
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -108,16 +108,22 @@ abstract public class BrowserApp extends
         public String icon;
         public boolean checkable = false;
         public boolean checked = false;
         public boolean enabled = true;
         public boolean visible = true;
         public int parent;
     }
 
+    // The types of guest mdoe dialogs we show
+    private static enum GuestModeDialog {
+        ENTERING,
+        LEAVING
+    }
+
     private Vector<MenuItemInfo> mAddonMenuItemsCache;
     private PropertyAnimator mMainLayoutAnimator;
 
     private static final Interpolator sTabsInterpolator = new Interpolator() {
         @Override
         public float getInterpolation(float t) {
             t -= 1.0f;
             return t * t * t * t * t + 1.0f;
@@ -1750,28 +1756,65 @@ abstract public class BrowserApp extends
                 return true;
             case R.id.new_tab:
                 addTab();
                 return true;
             case R.id.new_private_tab:
                 addPrivateTab();
                 return true;
             case R.id.enter_guest_mode:
-                doRestart("--guest-mode");
-                System.exit(0);
+                showGuestModeDialog(GuestModeDialog.ENTERING);
                 return true;
             case R.id.exit_guest_mode:
-                doRestart();
-                System.exit(0);
+                showGuestModeDialog(GuestModeDialog.LEAVING);
                 return true;
             default:
                 return super.onOptionsItemSelected(item);
         }
     }
 
+    private void showGuestModeDialog(final GuestModeDialog type) {
+        final Prompt ps = new Prompt(this, new Prompt.PromptCallback() {
+            @Override
+            public void onPromptFinished(String result) {
+                try {
+                    int itemId = new JSONObject(result).getInt("button");
+                    if (itemId == 0) {
+                        String args = "";
+                        if (type == GuestModeDialog.ENTERING) {
+                            args = "--guest-mode";
+                        }
+                        doRestart(args);
+                        System.exit(0);
+                    }
+                } catch(JSONException ex) {
+                    Log.e(LOGTAG, "Exception reading guest mode prompt result", ex);
+                }
+            }
+        });
+
+        Resources res = getResources();
+        ps.setButtons(new String[] {
+            res.getString(R.string.guest_mode_dialog_continue),
+            res.getString(R.string.guest_mode_dialog_cancel)
+        });
+
+        int titleString = 0;
+        int msgString = 0;
+        if (type == GuestModeDialog.ENTERING) {
+            titleString = R.string.guest_mode_enter_title;
+            msgString = R.string.guest_mode_enter_text;
+        } else {
+            titleString = R.string.guest_mode_leave_title;
+            msgString = R.string.guest_mode_leave_text;
+        }
+
+        ps.show(res.getString(titleString), res.getString(msgString), null, false);
+    }
+
     /**
      * This will detect if the key pressed is back. If so, will show the history.
      */
     @Override
     public boolean onKeyLongPress(int keyCode, KeyEvent event) {
         if (keyCode == KeyEvent.KEYCODE_BACK) {
             Tab tab = Tabs.getInstance().getSelectedTab();
             if (tab != null) {
--- a/mobile/android/base/Prompt.java
+++ b/mobile/android/base/Prompt.java
@@ -70,17 +70,16 @@ public class Prompt implements OnClickLi
     private static int mGroupPaddingSize;
     private static int mLeftRightTextWithIconPadding;
     private static int mTopBottomTextWithIconPadding;
     private static int mIconTextPadding;
     private static int mIconSize;
     private static int mInputPaddingSize;
     private static int mMinRowSize;
 
-
     public Prompt(Context context, ConcurrentLinkedQueue<String> queue) {
         this(context);
         mCallback = null;
         mPromptQueue = queue;
     }
 
     public Prompt(Context context, PromptCallback callback) {
         this(context);
@@ -207,16 +206,24 @@ public class Prompt implements OnClickLi
             }
         }
 
         mDialog = builder.create();
         mDialog.setOnCancelListener(Prompt.this);
         mDialog.show();
     }
 
+    public void setButtons(String[] buttons) {
+        mButtons = buttons;
+    }
+
+    public void setInputs(PromptInput[] inputs) {
+        mInputs = inputs;
+    }
+
     @Override
     public void onClick(DialogInterface aDialog, int aWhich) {
         ThreadUtils.assertOnUiThread();
         JSONObject ret = new JSONObject();
         try {
             int button = -1;
             ListView list = mDialog.getListView();
             if (list != null || mSelected != null) {
--- a/mobile/android/base/locales/en-US/android_strings.dtd
+++ b/mobile/android/base/locales/en-US/android_strings.dtd
@@ -347,10 +347,17 @@ just addresses the organization to follo
 <!ENTITY updater_downloading_title_failed2 "Download failed">
 <!ENTITY updater_downloading_select2 "Touch to apply update once downloaded">
 <!ENTITY updater_downloading_retry2 "Touch to retry">
 
 <!ENTITY updater_apply_title2 "Update available for &brandShortName;">
 <!ENTITY updater_apply_select2 "Touch to update">
 
 <!-- Guest mode -->
-<!ENTITY enter_guest_mode "Enter Guest Mode">
-<!ENTITY exit_guest_mode "Exit Guest Mode">
+<!ENTITY enter_guest_mode "Enter guest mode">
+<!ENTITY exit_guest_mode "Leave guest mode">
+<!ENTITY guest_mode_dialog_continue "Continue">
+<!ENTITY guest_mode_dialog_cancel "Cancel">
+<!ENTITY guest_mode_enter_title "Guest mode">
+<!ENTITY guest_mode_enter_text "While in guest mode, the person using &brandShortName; will not be able to see any of your personal browsing data (like your saved passwords, history or bookmarks).\n\nWhen your guest is done, their browsing data will be deleted.">
+
+<!ENTITY guest_mode_leave_title "Leaving guest mode">
+<!ENTITY guest_mode_leave_text "&brandShortName; will delete browsing data from this session.">
--- a/mobile/android/base/strings.xml.in
+++ b/mobile/android/base/strings.xml.in
@@ -318,9 +318,16 @@
 
   <!-- Contacts API -->
   <string name="contacts_account_chooser_dialog_title">Share contacts from...</string>
 
 
   <!-- Guest mode -->
   <string name="enter_guest_mode">&enter_guest_mode;</string>
   <string name="exit_guest_mode">&exit_guest_mode;</string>
+  <string name="guest_mode_dialog_continue">&guest_mode_dialog_continue;</string>
+  <string name="guest_mode_dialog_cancel">&guest_mode_dialog_cancel;</string>
+  <string name="guest_mode_enter_title">&guest_mode_enter_title;</string>
+  <string name="guest_mode_enter_text">&guest_mode_enter_text;</string>
+
+  <string name="guest_mode_leave_title">&guest_mode_leave_title;</string>
+  <string name="guest_mode_leave_text">&guest_mode_leave_text;</string>
 </resources>