Bug 762064 - Part 3: Add toast notification for cleared private data. r=blassey
authorBrian Nicholson <bnicholson@mozilla.com>
Tue, 26 Jun 2012 23:15:24 -0700
changeset 100478 dfced0e2fdaf01caba89de29aa8c3f3d101e2d7f
parent 100477 03cd608177cc216c3af3c73cfeda9527903880bd
child 100479 81cf04b16eb19ab624a8e372d7463ffc327beb4c
push idunknown
push userunknown
push dateunknown
reviewersblassey
bugs762064
milestone16.0a1
Bug 762064 - Part 3: Add toast notification for cleared private data. r=blassey
mobile/android/base/GeckoPreferences.java
mobile/android/base/locales/en-US/android_strings.dtd
mobile/android/base/strings.xml.in
mobile/android/chrome/content/browser.js
--- a/mobile/android/base/GeckoPreferences.java
+++ b/mobile/android/base/GeckoPreferences.java
@@ -19,16 +19,17 @@ import android.preference.*;
 import android.preference.Preference.*;
 import android.text.InputType;
 import android.util.Log;
 import android.view.MenuItem;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.EditText;
 import android.widget.LinearLayout;
+import android.widget.Toast;
 import android.text.TextWatcher;
 import android.text.TextUtils;
 import android.content.DialogInterface;
 
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 
@@ -42,16 +43,17 @@ public class GeckoPreferences
     private PreferenceScreen mPreferenceScreen;
     private static boolean sIsCharEncodingEnabled = false;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         addPreferencesFromResource(R.xml.preferences);
         GeckoAppShell.registerGeckoEventListener("Preferences:Data", this);
+        GeckoAppShell.registerGeckoEventListener("Sanitize:Finished", this);
    }
 
    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
         if (!hasFocus)
             return;
 
         mPreferencesList = new ArrayList<String>();
@@ -59,23 +61,33 @@ public class GeckoPreferences
         initGroups(mPreferenceScreen);
         initValues();
     }
 
     @Override
     protected void onDestroy() {
         super.onDestroy();
         GeckoAppShell.unregisterGeckoEventListener("Preferences:Data", this);
+        GeckoAppShell.unregisterGeckoEventListener("Sanitize:Finished", this);
     }
 
     public void handleMessage(String event, JSONObject message) {
         try {
             if (event.equals("Preferences:Data")) {
                 JSONArray jsonPrefs = message.getJSONArray("preferences");
                 refresh(jsonPrefs);
+            } else if (event.equals("Sanitize:Finished")) {
+                boolean success = message.getBoolean("success");
+                final int stringRes = success ? R.string.private_data_success : R.string.private_data_fail;
+                final Context context = this;
+                GeckoAppShell.getMainHandler().post(new Runnable () {
+                    public void run() {
+                        Toast.makeText(context, stringRes, Toast.LENGTH_SHORT).show();
+                    }
+                });
             }
         } catch (Exception e) {
             Log.e(LOGTAG, "Exception handling message \"" + event + "\":", e);
         }
     }
 
     // Initialize preferences by sending the "Preferences:Get" command to Gecko
     private void initValues() {
--- a/mobile/android/base/locales/en-US/android_strings.dtd
+++ b/mobile/android/base/locales/en-US/android_strings.dtd
@@ -180,16 +180,19 @@ which is run by
 Example Enterprises, Inc.
 
 The layout of the identity dialog prevents combining this into a single string with
 substitution variables.  If it is difficult to translate the sense of the string
 with that structure, consider a translation which ignores the preceding domain and
 just addresses the organization to follow, e.g. "This site is run by " -->
 <!ENTITY identity_run_by "which is run by">
 
+<!ENTITY private_data_success "Private data cleared">
+<!ENTITY private_data_fail "Some private data could not be cleared">
+
 <!ENTITY bookmarkhistory_button_import "Import">
 <!ENTITY bookmarkhistory_import_both "Importing bookmarks and history
                                       from Android">
 <!ENTITY bookmarkhistory_import_bookmarks "Importing bookmarks
                                            from Android">
 <!ENTITY bookmarkhistory_import_history "Importing history
                                          from Android">
 <!ENTITY bookmarkhistory_import_wait "Please wait...">
--- a/mobile/android/base/strings.xml.in
+++ b/mobile/android/base/strings.xml.in
@@ -185,16 +185,20 @@
 
   <string name="bookmarkdefaults_title_abouthome">@bookmarks_aboutHome@</string>
   <string name="bookmarkdefaults_url_abouthome">about:home</string>
 
   <!-- Site identity popup -->
   <string name="identity_connected_to">&identity_connected_to;</string>
   <string name="identity_run_by">&identity_run_by;</string>
 
+  <!-- Clear private data -->
+  <string name="private_data_success">&private_data_success;</string>
+  <string name="private_data_fail">&private_data_fail;</string>
+
   <!-- Bookmark import/export -->
   <string name="bookmarkhistory_button_import">&bookmarkhistory_button_import;</string>
   <string name="bookmarkhistory_import_both">&bookmarkhistory_import_both;</string>
   <string name="bookmarkhistory_import_bookmarks">&bookmarkhistory_import_bookmarks;</string>
   <string name="bookmarkhistory_import_history">&bookmarkhistory_import_history;</string>
   <string name="bookmarkhistory_import_wait">&bookmarkhistory_import_wait;</string>
 
 </resources>
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -778,27 +778,36 @@ var BrowserApp = {
       pref.data = json.value;
       Services.prefs.setComplexValue(json.name, Ci.nsISupportsString, pref);
     }
   },
 
   sanitize: function (aItems) {
     let sanitizer = new Sanitizer();
     let json = JSON.parse(aItems);
+    let success = true;
 
     for (let key in json) {
       if (!json[key])
         continue;
 
       try {
         sanitizer.clearItem(key);
       } catch (e) {
         dump("sanitize error: " + e);
+        success = false;
       }
     }
+
+    sendMessageToJava({
+      gecko: {
+        type: "Sanitize:Finished",
+        success: success
+      }
+    });
   },
 
   scrollToFocusedInput: function(aBrowser) {
     let doc = aBrowser.contentDocument;
     if (!doc)
       return;
 
     let focused = doc.activeElement;