mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1078395 - Work around missing profile in RestrictedProfiles. r=mfinkle
This is a partial fix; it avoids a crash, but isn't necessarily correct.
This commit is contained in:
parent
c980797db3
commit
b58fc1f490
@ -2666,12 +2666,12 @@ public class BrowserApp extends GeckoApp
|
||||
}
|
||||
|
||||
// Disable share menuitem for about:, chrome:, file:, and resource: URIs
|
||||
final boolean shareEnabled = RestrictedProfiles.isAllowed(RestrictedProfiles.Restriction.DISALLOW_SHARE);
|
||||
final boolean shareEnabled = RestrictedProfiles.isAllowed(this, RestrictedProfiles.Restriction.DISALLOW_SHARE);
|
||||
share.setVisible(shareEnabled);
|
||||
share.setEnabled(StringUtils.isShareableUrl(url) && shareEnabled);
|
||||
MenuUtils.safeSetEnabled(aMenu, R.id.apps, RestrictedProfiles.isAllowed(RestrictedProfiles.Restriction.DISALLOW_INSTALL_APPS));
|
||||
MenuUtils.safeSetEnabled(aMenu, R.id.addons, RestrictedProfiles.isAllowed(RestrictedProfiles.Restriction.DISALLOW_INSTALL_EXTENSION));
|
||||
MenuUtils.safeSetEnabled(aMenu, R.id.downloads, RestrictedProfiles.isAllowed(RestrictedProfiles.Restriction.DISALLOW_DOWNLOADS));
|
||||
MenuUtils.safeSetEnabled(aMenu, R.id.apps, RestrictedProfiles.isAllowed(this, RestrictedProfiles.Restriction.DISALLOW_INSTALL_APPS));
|
||||
MenuUtils.safeSetEnabled(aMenu, R.id.addons, RestrictedProfiles.isAllowed(this, RestrictedProfiles.Restriction.DISALLOW_INSTALL_EXTENSION));
|
||||
MenuUtils.safeSetEnabled(aMenu, R.id.downloads, RestrictedProfiles.isAllowed(this, RestrictedProfiles.Restriction.DISALLOW_DOWNLOADS));
|
||||
|
||||
// NOTE: Use MenuUtils.safeSetEnabled because some actions might
|
||||
// be on the BrowserToolbar context menu.
|
||||
|
@ -25,7 +25,7 @@ import android.util.Log;
|
||||
public class RestrictedProfiles {
|
||||
private static final String LOGTAG = "GeckoRestrictedProfiles";
|
||||
|
||||
private static Boolean inGuest = null;
|
||||
private static volatile Boolean inGuest = null;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private static final List<String> BANNED_SCHEMES = new ArrayList<String>() {{
|
||||
@ -36,6 +36,16 @@ public class RestrictedProfiles {
|
||||
add("wyciwyg");
|
||||
}};
|
||||
|
||||
/**
|
||||
* This is a hack to allow non-GeckoApp activities to safely call into
|
||||
* RestrictedProfiles without reworking this class or GeckoProfile.
|
||||
*
|
||||
* It can be removed after Bug 1077590 lands.
|
||||
*/
|
||||
public static void initWithProfile(GeckoProfile profile) {
|
||||
inGuest = profile.inGuestMode();
|
||||
}
|
||||
|
||||
private static boolean getInGuest() {
|
||||
if (inGuest == null) {
|
||||
inGuest = GeckoAppShell.getGeckoInterface().getProfile().inGuestMode();
|
||||
@ -86,9 +96,8 @@ public class RestrictedProfiles {
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
|
||||
@RobocopTarget
|
||||
private static Bundle getRestrictions() {
|
||||
final UserManager mgr = (UserManager) GeckoAppShell.getContext().getSystemService(Context.USER_SERVICE);
|
||||
private static Bundle getRestrictions(final Context context) {
|
||||
final UserManager mgr = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||
return mgr.getUserRestrictions();
|
||||
}
|
||||
|
||||
@ -101,17 +110,17 @@ public class RestrictedProfiles {
|
||||
*
|
||||
* Returns true otherwise.
|
||||
*/
|
||||
private static boolean getRestriction(final String name) {
|
||||
private static boolean getRestriction(final Context context, final String name) {
|
||||
// Early versions don't support restrictions at all,
|
||||
// so no action can be restricted.
|
||||
if (Versions.preJBMR2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return getRestrictions().getBoolean(name, false);
|
||||
return getRestrictions(context).getBoolean(name, false);
|
||||
}
|
||||
|
||||
private static boolean canLoadUrl(final String url) {
|
||||
private static boolean canLoadUrl(final Context context, final String url) {
|
||||
// Null URLs are always permitted.
|
||||
if (url == null) {
|
||||
return true;
|
||||
@ -120,7 +129,7 @@ public class RestrictedProfiles {
|
||||
try {
|
||||
// If we're not in guest mode, and the system restriction isn't in place, everything is allowed.
|
||||
if (!getInGuest() &&
|
||||
!getRestriction(Restriction.DISALLOW_BROWSE_FILES.name)) {
|
||||
!getRestriction(context, Restriction.DISALLOW_BROWSE_FILES.name)) {
|
||||
return true;
|
||||
}
|
||||
} catch (IllegalArgumentException ex) {
|
||||
@ -145,6 +154,10 @@ public class RestrictedProfiles {
|
||||
|
||||
@WrapElementForJNI
|
||||
public static boolean isUserRestricted() {
|
||||
return isUserRestricted(GeckoAppShell.getContext());
|
||||
}
|
||||
|
||||
private static boolean isUserRestricted(final Context context) {
|
||||
// Guest mode is supported in all Android versions.
|
||||
if (getInGuest()) {
|
||||
return true;
|
||||
@ -154,15 +167,19 @@ public class RestrictedProfiles {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !getRestrictions().isEmpty();
|
||||
return !getRestrictions(context).isEmpty();
|
||||
}
|
||||
|
||||
public static boolean isAllowed(Restriction action) {
|
||||
return isAllowed(action.id, null);
|
||||
public static boolean isAllowed(final Context context, final Restriction action) {
|
||||
return isAllowed(context, action.id, null);
|
||||
}
|
||||
|
||||
@WrapElementForJNI
|
||||
public static boolean isAllowed(int action, String url) {
|
||||
return isAllowed(GeckoAppShell.getContext(), action, url);
|
||||
}
|
||||
|
||||
private static boolean isAllowed(final Context context, int action, String url) {
|
||||
final Restriction restriction;
|
||||
try {
|
||||
restriction = geckoActionToRestriction(action);
|
||||
@ -175,7 +192,7 @@ public class RestrictedProfiles {
|
||||
|
||||
if (getInGuest()) {
|
||||
if (Restriction.DISALLOW_BROWSE_FILES == restriction) {
|
||||
return canLoadUrl(url);
|
||||
return canLoadUrl(context, url);
|
||||
}
|
||||
|
||||
// Guest users can't do anything.
|
||||
@ -183,11 +200,15 @@ public class RestrictedProfiles {
|
||||
}
|
||||
|
||||
// NOTE: Restrictions hold the opposite intention, so we need to flip it.
|
||||
return !getRestriction(restriction.name);
|
||||
return !getRestriction(context, restriction.name);
|
||||
}
|
||||
|
||||
@WrapElementForJNI
|
||||
public static String getUserRestrictions() {
|
||||
return getUserRestrictions(GeckoAppShell.getContext());
|
||||
}
|
||||
|
||||
private static String getUserRestrictions(final Context context) {
|
||||
// Guest mode is supported in all Android versions
|
||||
if (getInGuest()) {
|
||||
StringBuilder builder = new StringBuilder("{ ");
|
||||
@ -205,7 +226,7 @@ public class RestrictedProfiles {
|
||||
}
|
||||
|
||||
final JSONObject json = new JSONObject();
|
||||
final Bundle restrictions = getRestrictions();
|
||||
final Bundle restrictions = getRestrictions(context);
|
||||
final Set<String> keys = restrictions.keySet();
|
||||
|
||||
for (String key : keys) {
|
||||
|
@ -85,7 +85,7 @@ class HomeConfigPrefsBackend implements HomeConfigBackend {
|
||||
|
||||
// We disable Synced Tabs for guest mode profiles.
|
||||
final PanelConfig remoteTabsEntry;
|
||||
if (RestrictedProfiles.isAllowed(RestrictedProfiles.Restriction.DISALLOW_MODIFY_ACCOUNTS)) {
|
||||
if (RestrictedProfiles.isAllowed(mContext, RestrictedProfiles.Restriction.DISALLOW_MODIFY_ACCOUNTS)) {
|
||||
remoteTabsEntry = createBuiltinPanelConfig(mContext, PanelType.REMOTE_TABS);
|
||||
} else {
|
||||
remoteTabsEntry = null;
|
||||
|
@ -26,7 +26,7 @@ class AndroidImportPreference extends MultiPrefMultiChoicePreference {
|
||||
|
||||
public static class Handler implements GeckoPreferences.PrefHandler {
|
||||
public boolean setupPref(Context context, Preference pref) {
|
||||
return RestrictedProfiles.isAllowed(Restriction.DISALLOW_IMPORT_SETTINGS);
|
||||
return RestrictedProfiles.isAllowed(context, Restriction.DISALLOW_IMPORT_SETTINGS);
|
||||
}
|
||||
|
||||
public void onChange(Context context, Preference pref, Object newValue) { }
|
||||
|
@ -296,6 +296,9 @@ OnSharedPreferenceChangeListener
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
// Make sure RestrictedProfiles is ready.
|
||||
RestrictedProfiles.initWithProfile(GeckoProfile.get(this));
|
||||
|
||||
if (GeckoProfile.get(this).inGuestMode()) {
|
||||
GuestSession.configureWindow(getWindow());
|
||||
}
|
||||
@ -700,7 +703,7 @@ OnSharedPreferenceChangeListener
|
||||
i--;
|
||||
continue;
|
||||
} else if (PREFS_DEVTOOLS_REMOTE_ENABLED.equals(key)) {
|
||||
if (!RestrictedProfiles.isAllowed(RestrictedProfiles.Restriction.DISALLOW_REMOTE_DEBUGGING)) {
|
||||
if (!RestrictedProfiles.isAllowed(this, RestrictedProfiles.Restriction.DISALLOW_REMOTE_DEBUGGING)) {
|
||||
preferences.removePreference(pref);
|
||||
i--;
|
||||
continue;
|
||||
@ -728,7 +731,7 @@ OnSharedPreferenceChangeListener
|
||||
listPref.setSummary(selectedEntry);
|
||||
continue;
|
||||
} else if (PREFS_SYNC.equals(key) &&
|
||||
!RestrictedProfiles.isAllowed(RestrictedProfiles.Restriction.DISALLOW_MODIFY_ACCOUNTS)) {
|
||||
!RestrictedProfiles.isAllowed(this, RestrictedProfiles.Restriction.DISALLOW_MODIFY_ACCOUNTS)) {
|
||||
// Don't show sync prefs while in guest mode.
|
||||
preferences.removePreference(pref);
|
||||
i--;
|
||||
|
@ -183,7 +183,7 @@ 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(RestrictedProfiles.Restriction.DISALLOW_MODIFY_ACCOUNTS)) {
|
||||
if (RestrictedProfiles.isAllowed(mContext, RestrictedProfiles.Restriction.DISALLOW_MODIFY_ACCOUNTS)) {
|
||||
// The initial icon is not the animated icon, because on Android
|
||||
// 4.4.2, the animation starts immediately (and can start at other
|
||||
// unpredictable times). See Bug 1015974.
|
||||
|
Loading…
Reference in New Issue
Block a user