Bug 1125290 - Hide private browsing support and all related UI. r=margaret

This commit is contained in:
Sebastian Kaspari 2015-07-30 19:55:18 +02:00
parent 5a340437a8
commit 189e8ec063
11 changed files with 87 additions and 27 deletions

View File

@ -3360,6 +3360,9 @@ public class BrowserApp extends GeckoApp
final boolean toolsVisible = RestrictedProfiles.isAllowed(this, Restriction.DISALLOW_TOOLS_MENU);
MenuUtils.safeSetVisible(aMenu, R.id.tools, toolsVisible);
final boolean privateTabVisible = RestrictedProfiles.isAllowed(this, Restriction.DISALLOW_PRIVATE_BROWSING);
MenuUtils.safeSetVisible(aMenu, R.id.new_private_tab, privateTabVisible);
// Disable save as PDF for about:home and xul pages.
saveAsPDF.setEnabled(!(isAboutHome(tab) ||
tab.getContentType().equals("application/vnd.mozilla.xul+xml") ||

View File

@ -7,14 +7,13 @@ package org.mozilla.gecko.home;
import java.util.EnumSet;
import org.json.JSONException;
import org.json.JSONObject;
import org.mozilla.gecko.EditBookmarkDialog;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.R;
import org.mozilla.gecko.ReaderModeUtils;
import org.mozilla.gecko.RestrictedProfiles;
import org.mozilla.gecko.Telemetry;
import org.mozilla.gecko.TelemetryContract;
import org.mozilla.gecko.db.BrowserDB;
@ -24,6 +23,7 @@ import org.mozilla.gecko.home.HomeContextMenuInfo.RemoveItemType;
import org.mozilla.gecko.home.HomePager.OnUrlOpenInBackgroundListener;
import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
import org.mozilla.gecko.home.TopSitesGridView.TopSitesGridContextMenuInfo;
import org.mozilla.gecko.restrictions.Restriction;
import org.mozilla.gecko.util.Clipboard;
import org.mozilla.gecko.util.StringUtils;
import org.mozilla.gecko.util.ThreadUtils;
@ -151,6 +151,10 @@ public abstract class HomeFragment extends Fragment {
if (!StringUtils.isShareableUrl(info.url) || GeckoProfile.get(getActivity()).inGuestMode()) {
menu.findItem(R.id.home_share).setVisible(false);
}
if (!RestrictedProfiles.isAllowed(view.getContext(), Restriction.DISALLOW_PRIVATE_BROWSING)) {
menu.findItem(R.id.home_open_private_tab).setVisible(false);
}
}
@Override

View File

@ -18,6 +18,7 @@ import java.util.Map;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.Locales;
import org.mozilla.gecko.R;
import org.mozilla.gecko.RestrictedProfiles;
import org.mozilla.gecko.Tab;
import org.mozilla.gecko.Tabs;
import org.mozilla.gecko.Telemetry;
@ -33,6 +34,7 @@ import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
import org.mozilla.gecko.home.PinSiteDialog.OnSiteSelectedListener;
import org.mozilla.gecko.home.TopSitesGridView.OnEditPinnedSiteListener;
import org.mozilla.gecko.home.TopSitesGridView.TopSitesGridContextMenuInfo;
import org.mozilla.gecko.restrictions.Restriction;
import org.mozilla.gecko.tiles.TilesRecorder;
import org.mozilla.gecko.tiles.Tile;
import org.mozilla.gecko.util.StringUtils;
@ -369,6 +371,10 @@ public class TopSitesPanel extends HomeFragment {
if (!StringUtils.isShareableUrl(info.url) || GeckoProfile.get(getActivity()).inGuestMode()) {
menu.findItem(R.id.home_share).setVisible(false);
}
if (!RestrictedProfiles.isAllowed(view.getContext(), Restriction.DISALLOW_PRIVATE_BROWSING)) {
menu.findItem(R.id.home_open_private_tab).setVisible(false);
}
}
@Override

View File

@ -697,3 +697,5 @@ just addresses the organization to follow, e.g. "This site is run by " -->
<!ENTITY restriction_disallow_devtools_description "Disallow usage of developer tools.">
<!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.">

View File

@ -133,6 +133,8 @@ OnSharedPreferenceChangeListener
public static final String PREFS_QRCODE_ENABLED = NON_PREF_PREFIX + "qrcode_enabled";
private static final String PREFS_DEVTOOLS = NON_PREF_PREFIX + "devtools.enabled";
private static final String PREFS_CUSTOMIZE_HOME = NON_PREF_PREFIX + "customize_home";
private static final String PREFS_TRACKING_PROTECTION_PRIVATE_BROWSING = "privacy.trackingprotection.pbmode.enabled";
private static final String PREFS_TRACKING_PROTECTION_LEARN_MORE = NON_PREF_PREFIX + "trackingprotection.learn_more";
private static final String ACTION_STUMBLER_UPLOAD_PREF = AppConstants.ANDROID_PACKAGE_NAME + ".STUMBLER_PREF";
@ -738,7 +740,7 @@ OnSharedPreferenceChangeListener
}
} else if (PREFS_OPEN_URLS_IN_PRIVATE.equals(key)) {
// Remove UI for opening external links in private browsing on non-Nightly builds.
if (!AppConstants.NIGHTLY_BUILD) {
if (!AppConstants.NIGHTLY_BUILD || !RestrictedProfiles.isAllowed(this, Restriction.DISALLOW_PRIVATE_BROWSING)) {
preferences.removePreference(pref);
i--;
continue;
@ -848,6 +850,18 @@ OnSharedPreferenceChangeListener
i--;
continue;
}
} else if (PREFS_TRACKING_PROTECTION_PRIVATE_BROWSING.equals(key)) {
if (!RestrictedProfiles.isAllowed(this, Restriction.DISALLOW_PRIVATE_BROWSING)) {
preferences.removePreference(pref);
i--;
continue;
}
} else if (PREFS_TRACKING_PROTECTION_LEARN_MORE.equals(key)) {
if (!RestrictedProfiles.isAllowed(this, Restriction.DISALLOW_PRIVATE_BROWSING)) {
preferences.removePreference(pref);
i--;
continue;
}
}
// Some Preference UI elements are not actually preferences,

View File

@ -22,10 +22,12 @@ public class RestrictedProfileConfiguration implements RestrictionConfiguration
Restriction.DISALLOW_REPORT_SITE_ISSUE,
Restriction.DISALLOW_IMPORT_SETTINGS,
Restriction.DISALLOW_DEVELOPER_TOOLS,
Restriction.DISALLOW_CUSTOMIZE_HOME
Restriction.DISALLOW_CUSTOMIZE_HOME,
Restriction.DISALLOW_PRIVATE_BROWSING
);
private static final String ABOUT_ADDONS = "about:addons";
private static final String ABOUT_PRIVATE_BROWSING = "about:privatebrowsing";
private Context context;
@ -43,6 +45,11 @@ public class RestrictedProfileConfiguration implements RestrictionConfiguration
if (!isAllowed(Restriction.DISALLOW_INSTALL_EXTENSION) && url.toLowerCase().startsWith(ABOUT_ADDONS)) {
return false;
}
if (!isAllowed(Restriction.DISALLOW_PRIVATE_BROWSING) && url.toLowerCase().startsWith(ABOUT_PRIVATE_BROWSING)) {
return false;
}
return true;
}

View File

@ -12,7 +12,7 @@ import android.content.Context;
/**
* This is a list of things we can restrict you from doing. Some of these are reflected in Android UserManager constants.
* Others are specific to us.
* These constants should be in sync with the ones from toolkit/components/parentalcontrols/nsIParentalControlServices.idl
* These constants should be in sync with the ones from toolkit/components/parentalcontrols/nsIParentalControlsService.idl
*/
public enum Restriction {
DISALLOW_DOWNLOADS(
@ -76,6 +76,12 @@ public enum Restriction {
15, "no_customize_home",
R.string.restriction_disallow_customize_home_title,
R.string.restriction_disallow_customize_home_description
),
DISALLOW_PRIVATE_BROWSING(
16, "no_private_browsing",
R.string.restriction_disallow_private_browsing_title,
R.string.restriction_disallow_private_browsing_description
);
public final int id;

View File

@ -553,6 +553,8 @@
<string name="restriction_disallow_devtools_description">&restriction_disallow_devtools_description;</string>
<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>
<!-- Miscellaneous -->
<string name="ellipsis">&ellipsis;</string>

View File

@ -9,14 +9,16 @@ import org.mozilla.gecko.AppConstants.Versions;
import org.mozilla.gecko.GeckoApp;
import org.mozilla.gecko.GeckoApplication;
import org.mozilla.gecko.R;
import org.mozilla.gecko.RestrictedProfiles;
import org.mozilla.gecko.Tab;
import org.mozilla.gecko.Tabs;
import org.mozilla.gecko.Telemetry;
import org.mozilla.gecko.TelemetryContract;
import org.mozilla.gecko.animation.PropertyAnimator;
import org.mozilla.gecko.Tab;
import org.mozilla.gecko.Tabs;
import org.mozilla.gecko.animation.ViewHelper;
import org.mozilla.gecko.lwt.LightweightTheme;
import org.mozilla.gecko.lwt.LightweightThemeDrawable;
import org.mozilla.gecko.restrictions.Restriction;
import org.mozilla.gecko.util.HardwareUtils;
import org.mozilla.gecko.widget.GeckoPopupMenu;
import org.mozilla.gecko.widget.IconTabWidget;
@ -139,6 +141,10 @@ public class TabsPanel extends LinearLayout
mTabWidget.addTab(R.drawable.tabs_normal, R.string.tabs_normal);
mTabWidget.addTab(R.drawable.tabs_private, R.string.tabs_private);
if (!RestrictedProfiles.isAllowed(mContext, Restriction.DISALLOW_PRIVATE_BROWSING)) {
mTabWidget.setVisibility(View.GONE);
}
mTabWidget.setTabSelectionListener(this);
mMenuButton = (ImageButton) findViewById(R.id.menu);
@ -166,7 +172,8 @@ public class TabsPanel extends LinearLayout
// Each panel has a "+" shortcut button, so don't show it for that panel.
menu.findItem(R.id.new_tab).setVisible(mCurrentPanel != Panel.NORMAL_TABS);
menu.findItem(R.id.new_private_tab).setVisible(mCurrentPanel != Panel.PRIVATE_TABS);
menu.findItem(R.id.new_private_tab).setVisible(mCurrentPanel != Panel.PRIVATE_TABS
&& RestrictedProfiles.isAllowed(mContext, Restriction.DISALLOW_PRIVATE_BROWSING));
// Only show "Clear * tabs" for current panel.
menu.findItem(R.id.close_all_tabs).setVisible(mCurrentPanel == Panel.NORMAL_TABS);

View File

@ -690,27 +690,35 @@ var BrowserApp = {
});
});
NativeWindow.contextmenus.add(stringGetter("contextmenu.openInPrivateTab"),
NativeWindow.contextmenus.linkOpenableContext,
function(aTarget) {
UITelemetry.addEvent("action.1", "contextmenu", null, "web_open_private_tab");
UITelemetry.addEvent("loadurl.1", "contextmenu", null);
let showOpenInPrivateTab = true;
if ("@mozilla.org/parental-controls-service;1" in Cc) {
let pc = Cc["@mozilla.org/parental-controls-service;1"].createInstance(Ci.nsIParentalControlsService);
showOpenInPrivateTab = pc.isAllowed(Ci.nsIParentalControlsService.PRIVATE_BROWSING);
}
let url = NativeWindow.contextmenus._getLinkURL(aTarget);
ContentAreaUtils.urlSecurityCheck(url, aTarget.ownerDocument.nodePrincipal);
let tab = BrowserApp.addTab(url, { selected: false, parentId: BrowserApp.selectedTab.id, isPrivate: true });
if (showOpenInPrivateTab) {
NativeWindow.contextmenus.add(stringGetter("contextmenu.openInPrivateTab"),
NativeWindow.contextmenus.linkOpenableContext,
function (aTarget) {
UITelemetry.addEvent("action.1", "contextmenu", null, "web_open_private_tab");
UITelemetry.addEvent("loadurl.1", "contextmenu", null);
let newtabStrings = Strings.browser.GetStringFromName("newprivatetabpopup.opened");
let label = PluralForm.get(1, newtabStrings).replace("#1", 1);
let buttonLabel = Strings.browser.GetStringFromName("newtabpopup.switch");
NativeWindow.toast.show(label, "long", {
button: {
icon: "drawable://switch_button_icon",
label: buttonLabel,
callback: () => { BrowserApp.selectTab(tab); },
}
let url = NativeWindow.contextmenus._getLinkURL(aTarget);
ContentAreaUtils.urlSecurityCheck(url, aTarget.ownerDocument.nodePrincipal);
let tab = BrowserApp.addTab(url, {selected: false, parentId: BrowserApp.selectedTab.id, isPrivate: true});
let newtabStrings = Strings.browser.GetStringFromName("newprivatetabpopup.opened");
let label = PluralForm.get(1, newtabStrings).replace("#1", 1);
let buttonLabel = Strings.browser.GetStringFromName("newtabpopup.switch");
NativeWindow.toast.show(label, "long", {
button: {
icon: "drawable://switch_button_icon",
label: buttonLabel,
callback: () => { BrowserApp.selectTab(tab); },
}
});
});
});
}
NativeWindow.contextmenus.add(stringGetter("contextmenu.addToReadingList"),
NativeWindow.contextmenus.linkOpenableContext,

View File

@ -11,7 +11,7 @@ interface nsIFile;
interface nsIInterfaceRequestor;
interface nsIArray;
[scriptable, uuid(406808a5-2838-4c29-9e39-5bfb885c89bf)]
[scriptable, uuid(95e1b8cc-c26b-4393-a27e-b630d46183a9)]
interface nsIParentalControlsService : nsISupports
{
/**
@ -30,6 +30,7 @@ interface nsIParentalControlsService : nsISupports
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
/**
* @returns true if the current user account has parental controls