Bug 1188905 - Restricted profiles: Prevent clearing history. r=margaret
authorSebastian Kaspari <s.kaspari@gmail.com>
Fri, 31 Jul 2015 09:59:01 +0200
changeset 287274 12855aeba4b75686e8772086994340a8cacae2a7
parent 287273 5ad2d34c58b16975117d385c324e6e40df83828f
child 287275 2fad87d96b1939673af34fae1f7431f485ec2ee2
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret
bugs1188905
milestone42.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 1188905 - Restricted profiles: Prevent clearing history. r=margaret
mobile/android/base/home/HistoryPanel.java
mobile/android/base/locales/en-US/android_strings.dtd
mobile/android/base/restrictions/RestrictedProfileConfiguration.java
mobile/android/base/restrictions/Restriction.java
mobile/android/base/strings.xml.in
toolkit/components/parentalcontrols/nsIParentalControlsService.idl
--- a/mobile/android/base/home/HistoryPanel.java
+++ b/mobile/android/base/home/HistoryPanel.java
@@ -5,28 +5,31 @@
 
 package org.mozilla.gecko.home;
 
 import java.util.Date;
 import java.util.EnumSet;
 
 import org.json.JSONException;
 import org.json.JSONObject;
+
 import org.mozilla.gecko.EventDispatcher;
 import org.mozilla.gecko.GeckoAppShell;
 import org.mozilla.gecko.GeckoEvent;
 import org.mozilla.gecko.GeckoProfile;
 import org.mozilla.gecko.R;
+import org.mozilla.gecko.RestrictedProfiles;
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
 import org.mozilla.gecko.db.BrowserContract.Combined;
 import org.mozilla.gecko.db.BrowserContract.History;
 import org.mozilla.gecko.db.BrowserDB;
 import org.mozilla.gecko.home.HomeContextMenuInfo.RemoveItemType;
 import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
+import org.mozilla.gecko.restrictions.Restriction;
 
 import android.app.AlertDialog;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.DialogInterface;
 import android.database.Cursor;
 import android.graphics.Typeface;
 import android.os.Bundle;
@@ -34,16 +37,17 @@ import android.support.v4.content.Loader
 import android.text.SpannableStringBuilder;
 import android.text.TextPaint;
 import android.text.method.LinkMovementMethod;
 import android.text.style.ClickableSpan;
 import android.text.style.StyleSpan;
 import android.text.style.UnderlineSpan;
 import android.util.Log;
 import android.util.SparseArray;
+import android.view.ContextMenu;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.ViewStub;
 import android.widget.AdapterView;
 import android.widget.ImageView;
 import android.widget.TextView;
 
@@ -157,16 +161,25 @@ public class HistoryPanel extends HomeFr
                 });
 
                 dialogBuilder.show();
             }
         });
     }
 
     @Override
+    public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
+        super.onCreateContextMenu(menu, view, menuInfo);
+
+        if (!RestrictedProfiles.isAllowed(getActivity(), Restriction.DISALLOW_CLEAR_HISTORY)) {
+            menu.findItem(R.id.home_remove).setVisible(false);
+        }
+    }
+
+    @Override
     public void onDestroyView() {
         super.onDestroyView();
         mList = null;
         mEmptyView = null;
         mClearHistoryButton = null;
     }
 
     @Override
@@ -201,17 +214,19 @@ public class HistoryPanel extends HomeFr
         public Cursor loadCursor() {
             final ContentResolver cr = getContext().getContentResolver();
             return mDB.getRecentHistory(cr, HISTORY_LIMIT);
         }
     }
 
     private void updateUiFromCursor(Cursor c) {
         if (c != null && c.getCount() > 0) {
-            mClearHistoryButton.setVisibility(View.VISIBLE);
+            if (RestrictedProfiles.isAllowed(getActivity(), Restriction.DISALLOW_CLEAR_HISTORY)) {
+                mClearHistoryButton.setVisibility(View.VISIBLE);
+            }
             return;
         }
 
         // Cursor is empty, so hide the "Clear browsing history" button,
         // and set the empty view if it hasn't been set already.
         mClearHistoryButton.setVisibility(View.GONE);
 
         if (mEmptyView == null) {
--- a/mobile/android/base/locales/en-US/android_strings.dtd
+++ b/mobile/android/base/locales/en-US/android_strings.dtd
@@ -698,8 +698,10 @@ just addresses the organization to follo
 <!ENTITY restriction_disallow_customize_home_title "Disallow customizing home">
 <!ENTITY restriction_disallow_customize_home_description "Disallow customizing home panels.">
 <!ENTITY restriction_disallow_private_browsing_title "Disallow private browsing">
 <!ENTITY restriction_disallow_private_browsing_description "Disallow private browsing mode.">
 <!ENTITY restriction_disallow_location_services_title "Disallow location services">
 <!ENTITY restriction_disallow_location_services_description "Disallow sharing of location data to improve geolocation service.">
 <!ENTITY restriction_disallow_display_settings_title "Disallow display settings">
 <!ENTITY restriction_disallow_display_settings_description "Disallow changing of advanced display settings.">
+<!ENTITY restriction_disallow_clear_history_title "Disallow clearing history">
+<!ENTITY restriction_disallow_clear_history_description "Disallow clearing of browser history.">
--- a/mobile/android/base/restrictions/RestrictedProfileConfiguration.java
+++ b/mobile/android/base/restrictions/RestrictedProfileConfiguration.java
@@ -20,17 +20,18 @@ public class RestrictedProfileConfigurat
             Restriction.DISALLOW_INSTALL_APPS,
             Restriction.DISALLOW_TOOLS_MENU,
             Restriction.DISALLOW_REPORT_SITE_ISSUE,
             Restriction.DISALLOW_IMPORT_SETTINGS,
             Restriction.DISALLOW_DEVELOPER_TOOLS,
             Restriction.DISALLOW_CUSTOMIZE_HOME,
             Restriction.DISALLOW_PRIVATE_BROWSING,
             Restriction.DISALLOW_LOCATION_SERVICE,
-            Restriction.DISALLOW_DISPLAY_SETTINGS
+            Restriction.DISALLOW_DISPLAY_SETTINGS,
+            Restriction.DISALLOW_CLEAR_HISTORY
     );
 
     private static final String ABOUT_ADDONS = "about:addons";
     private static final String ABOUT_PRIVATE_BROWSING = "about:privatebrowsing";
 
     private Context context;
 
     public RestrictedProfileConfiguration(Context context) {
--- a/mobile/android/base/restrictions/Restriction.java
+++ b/mobile/android/base/restrictions/Restriction.java
@@ -89,16 +89,22 @@ public enum Restriction {
             R.string.restriction_disallow_location_services_title,
             R.string.restriction_disallow_location_services_description
     ),
 
     DISALLOW_DISPLAY_SETTINGS(
             18, "no_display_settings",
             R.string.restriction_disallow_display_settings_title,
             R.string.restriction_disallow_display_settings_description
+    ),
+
+    DISALLOW_CLEAR_HISTORY(
+            19, "no_clear_history",
+            R.string.restriction_disallow_clear_history_title,
+            R.string.restriction_disallow_clear_history_description
     );
 
     public final int id;
     public final String name;
     public final int titleResource;
     public final int descriptionResource;
 
     Restriction(final int id, final String name, int titleResource, int descriptionResource) {
--- a/mobile/android/base/strings.xml.in
+++ b/mobile/android/base/strings.xml.in
@@ -554,16 +554,18 @@
   <string name="restriction_disallow_customize_home_title">&restriction_disallow_customize_home_title;</string>
   <string name="restriction_disallow_customize_home_description">&restriction_disallow_customize_home_description;</string>
   <string name="restriction_disallow_private_browsing_title">&restriction_disallow_private_browsing_title;</string>
   <string name="restriction_disallow_private_browsing_description">&restriction_disallow_private_browsing_description;</string>
   <string name="restriction_disallow_location_services_title">&restriction_disallow_location_services_title;</string>
   <string name="restriction_disallow_location_services_description">&restriction_disallow_location_services_description;</string>
   <string name="restriction_disallow_display_settings_title">&restriction_disallow_display_settings_title;</string>
   <string name="restriction_disallow_display_settings_description">&restriction_disallow_display_settings_description;</string>
+  <string name="restriction_disallow_clear_history_title">&restriction_disallow_clear_history_title;</string>
+  <string name="restriction_disallow_clear_history_description">&restriction_disallow_clear_history_description;</string>
 
   <!-- Miscellaneous -->
   <string name="ellipsis">&ellipsis;</string>
 
   <string name="colon">&colon;</string>
 
   <string name="percent">&percent;</string>
 
--- a/toolkit/components/parentalcontrols/nsIParentalControlsService.idl
+++ b/toolkit/components/parentalcontrols/nsIParentalControlsService.idl
@@ -6,17 +6,17 @@
 
 #include "nsISupports.idl"
 
 interface nsIURI;
 interface nsIFile;
 interface nsIInterfaceRequestor;
 interface nsIArray;
 
-[scriptable, uuid(6f0127f8-3066-45ad-b0f4-8bb718252273)]
+[scriptable, uuid(7091a3af-30be-4cf7-a48c-347071d61b5e)]
 interface nsIParentalControlsService : nsISupports
 {
   /**
    * Action types that can be blocked for users.
    */
   const short DOWNLOAD = 1; // Downloading files
   const short INSTALL_EXTENSION = 2; // Installing extensions
   const short INSTALL_APP = 3; // Installing webapps
@@ -28,16 +28,17 @@ interface nsIParentalControlsService : n
   const short MODIFY_ACCOUNTS = 9; // Modifying system accounts
   const short REMOTE_DEBUGGING = 10; // Remote debugging
   const short IMPORT_SETTINGS = 11; // Importing settings from other apps
   const short TOOLS_MENU = 12; // Hide tools menu entry
   const short REPORT_SITE_ISSUE = 13; // Hide "Report Site Issue" menu entry
   const short PRIVATE_BROWSING = 16; // Disallow usage of private browsing
   const short LOCATION_SERVICE = 17; // Sharing of location data to location service
   const short DISPLAY_SETTINGS = 18; // Website display settings
+  const short CLEAR_HISTORY = 19; // Clear browsing history
 
   /**
    * @returns true if the current user account has parental controls
    * restrictions enabled.
    */
   readonly attribute boolean parentalControlsEnabled;
 
   /**