Bug 1058150 - Use restricted profiles for guest mode. r=mfinkle

This commit is contained in:
Wes Johnston 2014-09-09 15:08:37 -07:00
Родитель acfe258d54
Коммит 03414226cb
18 изменённых файлов: 348 добавлений и 122 удалений

Просмотреть файл

@ -2556,12 +2556,12 @@ public class BrowserApp extends GeckoApp
}
// Disable share menuitem for about:, chrome:, file:, and resource: URIs
final boolean inGuestMode = GeckoProfile.get(this).inGuestMode();
share.setVisible(!inGuestMode);
share.setEnabled(StringUtils.isShareableUrl(url) && !inGuestMode);
MenuUtils.safeSetEnabled(aMenu, R.id.apps, !inGuestMode);
MenuUtils.safeSetEnabled(aMenu, R.id.addons, !inGuestMode);
MenuUtils.safeSetEnabled(aMenu, R.id.downloads, !inGuestMode);
final boolean shareEnabled = RestrictedProfiles.isAllowed(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_EXTENSIONS));
MenuUtils.safeSetEnabled(aMenu, R.id.downloads, RestrictedProfiles.isAllowed(RestrictedProfiles.Restriction.DISALLOW_DOWNLOADS));
// NOTE: Use MenuUtils.safeSetEnabled because some actions might
// be on the BrowserToolbar context menu.

Просмотреть файл

@ -104,7 +104,6 @@ import android.os.Looper;
import android.os.Message;
import android.os.MessageQueue;
import android.os.SystemClock;
import android.os.UserManager;
import android.os.Vibrator;
import android.provider.Settings;
import android.telephony.TelephonyManager;
@ -2554,39 +2553,6 @@ public class GeckoAppShell
return "DIRECT";
}
@WrapElementForJNI
public static boolean isUserRestricted() {
if (Versions.preJBMR2) {
return false;
}
UserManager mgr = (UserManager)getContext().getSystemService(Context.USER_SERVICE);
Bundle restrictions = mgr.getUserRestrictions();
return !restrictions.isEmpty();
}
@WrapElementForJNI
public static String getUserRestrictions() {
if (Versions.preJBMR2) {
return "{}";
}
JSONObject json = new JSONObject();
UserManager mgr = (UserManager)getContext().getSystemService(Context.USER_SERVICE);
Bundle restrictions = mgr.getUserRestrictions();
Set<String> keys = restrictions.keySet();
for (String key : keys) {
try {
json.put(key, restrictions.get(key));
} catch (JSONException e) {
}
}
return json.toString();
}
/* Downloads the uri pointed to by a share intent, and alters the intent to point to the locally stored file.
*/
public static void downloadImageForIntent(final Intent intent) {

Просмотреть файл

@ -0,0 +1,132 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko;
import android.content.Context;
import android.os.Bundle;
import android.os.UserManager;
import android.util.Log;
import java.lang.StringBuilder;
import java.util.HashSet;
import java.util.Set;
import org.json.JSONException;
import org.json.JSONObject;
import org.mozilla.gecko.AppConstants.Versions;
import org.mozilla.gecko.mozglue.generatorannotations.WrapElementForJNI;
public class RestrictedProfiles {
private static final String LOGTAG = "GeckoRestrictedProfiles";
// These constants should be in sync with the ones from toolkit/components/parentalcontrols/nsIParentalControlServices.java
public static enum Restriction {
DISALLOW_DOWNLOADS(1, "no_download_files"),
DISALLOW_INSTALL_EXTENSIONS(2, "no_install_extensions"),
DISALLOW_INSTALL_APPS(3, UserManager.DISALLOW_INSTALL_APPS),
DISALLOW_BROWSE_FILES(4, "no_browse_files"),
DISALLOW_SHARE(5, "no_share"),
DISALLOW_BOOKMARK(6, "no_bookmark"),
DISALLOW_ADD_CONTACTS(7, "no_add_contacts"),
DISALLOW_SET_IMAGE(8, "no_set_image");
public final int id;
public final String name;
private Restriction(final int id, final String name) {
this.id = id;
this.name = name;
}
}
private static String geckoActionToRestrction(int action) {
for (Restriction rest : Restriction.values()) {
if (rest.id == action) {
return rest.name;
}
}
throw new IllegalArgumentException("Unknown action " + action);
}
private static Bundle getRestrctions() {
final UserManager mgr = (UserManager) GeckoAppShell.getContext().getSystemService(Context.USER_SERVICE);
return mgr.getUserRestrictions();
}
@WrapElementForJNI
public static boolean isUserRestricted() {
// Guest mode is supported in all Android versions
if (GeckoAppShell.getGeckoInterface().getProfile().inGuestMode()) {
return true;
}
if (Versions.preJBMR2) {
return false;
}
return !getRestrctions().isEmpty();
}
public static boolean isAllowed(Restriction action) {
return isAllowed(action.id, null);
}
@WrapElementForJNI
public static boolean isAllowed(int action, String url) {
// ALl actions are blocked in Guest mode
if (GeckoAppShell.getGeckoInterface().getProfile().inGuestMode()) {
return false;
}
if (Versions.preJBMR2) {
return true;
}
try {
final String restriction = geckoActionToRestrction(action);
return !getRestrctions().getBoolean(restriction, false);
} catch(IllegalArgumentException ex) {
Log.i(LOGTAG, "Invalid action", ex);
}
return true;
}
@WrapElementForJNI
public static String getUserRestrictions() {
// Guest mode is supported in all Android versions
if (GeckoAppShell.getGeckoInterface().getProfile().inGuestMode()) {
StringBuilder builder = new StringBuilder("{ ");
for (Restriction restriction : Restriction.values()) {
builder.append("\"" + restriction.name + "\": true, ");
}
builder.append(" }");
return builder.toString();
}
if (Versions.preJBMR2) {
return "{}";
}
final JSONObject json = new JSONObject();
final Bundle restrictions = getRestrctions();
final Set<String> keys = restrictions.keySet();
for (String key : keys) {
try {
json.put(key, restrictions.get(key));
} catch (JSONException e) {
}
}
return json.toString();
}
}

Просмотреть файл

@ -369,6 +369,7 @@ gbjar.sources += [
'ReaderModeUtils.java',
'RemoteTabsExpandableListAdapter.java',
'Restarter.java',
'RestrictedProfiles.java',
'ScrollAnimator.java',
'ServiceNotificationClient.java',
'SessionParser.java',

Просмотреть файл

@ -18,28 +18,38 @@ add_task(function test_isUserRestricted() {
// In a restricted profile: enabled = true
do_check_false(pc.parentalControlsEnabled);
//run_next_test();
do_check_true(pc.isAllowed(Ci.nsIParentalControlsService.DOWNLOAD));
do_check_true(pc.isAllowed(Ci.nsIParentalControlsService.INSTALL_EXTENSION));
do_check_true(pc.isAllowed(Ci.nsIParentalControlsService.INSTALL_APP));
do_check_true(pc.isAllowed(Ci.nsIParentalControlsService.VISIT_FILE_URLS));
do_check_true(pc.isAllowed(Ci.nsIParentalControlsService.SHARE));
do_check_true(pc.isAllowed(Ci.nsIParentalControlsService.BOOKMARK));
do_check_true(pc.isAllowed(Ci.nsIParentalControlsService.INSTALL_EXTENSION));
run_next_test();
});
/*
// NOTE: JNI.jsm has no way to call a string method yet
add_task(function test_getUserRestrictions() {
// In an admin profile, like the tests: {}
// In a restricted profile: {"no_modify_accounts":true,"no_share_location":true}
let restrictions = "{}";
let jni = null;
var jenv = null;
try {
jni = new JNI();
let cls = jni.findClass("org/mozilla/gecko/GeckoAppShell");
let method = jni.getStaticMethodID(cls, "getUserRestrictions", "()Ljava/lang/String;");
restrictions = jni.callStaticStringMethod(cls, method);
jenv = JNI.GetForThread();
var geckoAppShell = JNI.LoadClass(jenv, "org.mozilla.gecko.RestrictedProfile", {
static_methods: [
{ name: "getUserRestrictions", sig: "()Ljava/lang/String;" },
],
});
restrictions = JNI.ReadString(jenv, geckoAppShell.getUserRestrictions());
} finally {
if (jni != null) {
jni.close();
if (jenv) {
JNI.UnloadClasses(jenv);
}
}
do_check_eq(restrictions, "{}");
});
*/
run_next_test();

Просмотреть файл

@ -652,6 +652,10 @@ var SelectionHandler = {
},
selector: {
matches: function() {
if (!ParentalControls.isAllowed(ParentalControls.SHARE)) {
return false;
}
return SelectionHandler.isSelectionActive();
}
}

Просмотреть файл

@ -164,6 +164,9 @@ XPCOMUtils.defineLazyModuleGetter(this, "NetErrorHelper",
XPCOMUtils.defineLazyServiceGetter(this, "Haptic",
"@mozilla.org/widget/hapticfeedback;1", "nsIHapticFeedback");
XPCOMUtils.defineLazyServiceGetter(this, "ParentalControls",
"@mozilla.org/parental-controls-service;1", "nsIParentalControlsService");
XPCOMUtils.defineLazyServiceGetter(this, "DOMUtils",
"@mozilla.org/inspector/dom-utils;1", "inIDOMUtils");
@ -287,7 +290,6 @@ var BrowserApp = {
_tabs: [],
_selectedTab: null,
_prefObservers: [],
isGuest: false,
get isTablet() {
let sysInfo = Cc["@mozilla.org/system-info;1"].getService(Ci.nsIPropertyBag2);
@ -434,8 +436,6 @@ var BrowserApp = {
gScreenHeight = window.arguments[2];
if (window.arguments[3])
pinned = window.arguments[3];
if (window.arguments[4])
this.isGuest = window.arguments[4];
}
if (pinned) {
@ -459,7 +459,7 @@ var BrowserApp = {
if (this._startupStatus)
this.onAppUpdated();
if (this.isGuest) {
if (!ParentalControls.isAllowed(ParentalControls.INSTALL_EXTENSIONS)) {
// Disable extension installs
Services.prefs.setIntPref("extensions.enabledScopes", 1);
Services.prefs.setIntPref("extensions.autoDisableScopes", 1);
@ -581,7 +581,7 @@ var BrowserApp = {
NativeWindow.contextmenus.add({
label: Strings.browser.GetStringFromName("contextmenu.shareLink"),
order: NativeWindow.contextmenus.DEFAULT_HTML5_ORDER - 1, // Show above HTML5 menu items
selector: NativeWindow.contextmenus._disableInGuest(NativeWindow.contextmenus.linkShareableContext),
selector: NativeWindow.contextmenus._disableRestricted("SHARE", NativeWindow.contextmenus.linkShareableContext),
showAsActions: function(aElement) {
return {
title: aElement.textContent.trim() || aElement.title.trim(),
@ -597,7 +597,7 @@ var BrowserApp = {
NativeWindow.contextmenus.add({
label: Strings.browser.GetStringFromName("contextmenu.shareEmailAddress"),
order: NativeWindow.contextmenus.DEFAULT_HTML5_ORDER - 1,
selector: NativeWindow.contextmenus._disableInGuest(NativeWindow.contextmenus.emailLinkContext),
selector: NativeWindow.contextmenus._disableRestricted("SHARE", NativeWindow.contextmenus.emailLinkContext),
showAsActions: function(aElement) {
let url = NativeWindow.contextmenus._getLinkURL(aElement);
let emailAddr = NativeWindow.contextmenus._stripScheme(url);
@ -616,7 +616,7 @@ var BrowserApp = {
NativeWindow.contextmenus.add({
label: Strings.browser.GetStringFromName("contextmenu.sharePhoneNumber"),
order: NativeWindow.contextmenus.DEFAULT_HTML5_ORDER - 1,
selector: NativeWindow.contextmenus._disableInGuest(NativeWindow.contextmenus.phoneNumberLinkContext),
selector: NativeWindow.contextmenus._disableRestricted("SHARE", NativeWindow.contextmenus.phoneNumberLinkContext),
showAsActions: function(aElement) {
let url = NativeWindow.contextmenus._getLinkURL(aElement);
let phoneNumber = NativeWindow.contextmenus._stripScheme(url);
@ -633,7 +633,7 @@ var BrowserApp = {
});
NativeWindow.contextmenus.add(Strings.browser.GetStringFromName("contextmenu.addToContacts"),
NativeWindow.contextmenus._disableInGuest(NativeWindow.contextmenus.emailLinkContext),
NativeWindow.contextmenus._disableRestricted("ADD_CONTACT", NativeWindow.contextmenus.emailLinkContext),
function(aTarget) {
UITelemetry.addEvent("action.1", "contextmenu", null, "web_contact_email");
@ -645,7 +645,7 @@ var BrowserApp = {
});
NativeWindow.contextmenus.add(Strings.browser.GetStringFromName("contextmenu.addToContacts"),
NativeWindow.contextmenus._disableInGuest(NativeWindow.contextmenus.phoneNumberLinkContext),
NativeWindow.contextmenus._disableRestricted("ADD_CONTACT", NativeWindow.contextmenus.phoneNumberLinkContext),
function(aTarget) {
UITelemetry.addEvent("action.1", "contextmenu", null, "web_contact_phone");
@ -657,7 +657,7 @@ var BrowserApp = {
});
NativeWindow.contextmenus.add(Strings.browser.GetStringFromName("contextmenu.bookmarkLink"),
NativeWindow.contextmenus._disableInGuest(NativeWindow.contextmenus.linkBookmarkableContext),
NativeWindow.contextmenus._disableRestricted("BOOKMARK", NativeWindow.contextmenus.linkBookmarkableContext),
function(aTarget) {
UITelemetry.addEvent("action.1", "contextmenu", null, "web_bookmark");
@ -694,7 +694,7 @@ var BrowserApp = {
NativeWindow.contextmenus.add({
label: Strings.browser.GetStringFromName("contextmenu.shareMedia"),
order: NativeWindow.contextmenus.DEFAULT_HTML5_ORDER - 1,
selector: NativeWindow.contextmenus._disableInGuest(NativeWindow.contextmenus.SelectorContext("video")),
selector: NativeWindow.contextmenus._disableRestricted("SHARE", NativeWindow.contextmenus.SelectorContext("video")),
showAsActions: function(aElement) {
let url = (aElement.currentSrc || aElement.src);
let title = aElement.textContent || aElement.title;
@ -742,7 +742,7 @@ var BrowserApp = {
NativeWindow.contextmenus.add({
label: Strings.browser.GetStringFromName("contextmenu.shareImage"),
selector: NativeWindow.contextmenus._disableInGuest(NativeWindow.contextmenus.imageSaveableContext),
selector: NativeWindow.contextmenus._disableRestricted("SHARE", NativeWindow.contextmenus.imageSaveableContext),
order: NativeWindow.contextmenus.DEFAULT_HTML5_ORDER - 1, // Show above HTML5 menu items
showAsActions: function(aTarget) {
let doc = aTarget.ownerDocument;
@ -774,7 +774,7 @@ var BrowserApp = {
});
NativeWindow.contextmenus.add(Strings.browser.GetStringFromName("contextmenu.setImageAs"),
NativeWindow.contextmenus._disableInGuest(NativeWindow.contextmenus.imageSaveableContext),
NativeWindow.contextmenus._disableRestricted("SET_IMAGE", NativeWindow.contextmenus.imageSaveableContext),
function(aTarget) {
UITelemetry.addEvent("action.1", "contextmenu", null, "web_background_image");
@ -2680,11 +2680,13 @@ var NativeWindow = {
return null;
},
_disableInGuest: function _disableInGuest(selector) {
_disableRestricted: function _disableRestricted(restriction, selector) {
return {
matches: function _disableInGuestMatches(aElement, aX, aY) {
if (BrowserApp.isGuest)
matches: function _disableRestrictedMatches(aElement, aX, aY) {
if (!ParentalControls.isAllowed(ParentalControls[restriction])) {
return false;
}
return selector.matches(aElement, aX, aY);
}
};
@ -4202,8 +4204,8 @@ Tab.prototype = {
fixedURI = URIFixup.createExposableURI(aLocationURI);
} catch (ex) { }
// In guest sessions, we refuse to let you open any file urls.
if (BrowserApp.isGuest) {
// In restricted profiles, we refuse to let you open any file urls.
if (!ParentalControls.isAllowed(ParentalControls.VISIT_FILE_URLS)) {
let bannedSchemes = ["file", "chrome", "resource", "jar", "wyciwyg"];
if (bannedSchemes.indexOf(fixedURI.scheme) > -1) {

Просмотреть файл

@ -256,11 +256,12 @@ AlertDownloadProgressListener.prototype = {
let state = aDownload.state;
switch (state) {
case Ci.nsIDownloadManager.DOWNLOAD_QUEUED: {
if (BrowserApp.isGuest) {
if (!ParentalControls.isAllowed(ParentalControls.DOWNLOADS)) {
aDownload.cancel();
NativeWindow.toast.show(Strings.browser.GetStringFromName("downloads.disabledInGuest"), "long");
return;
}
NativeWindow.toast.show(Strings.browser.GetStringFromName("alertDownloadsToast"), "long");
Downloads.createNotification(aDownload, new DownloadNotifOptions(aDownload,
Strings.browser.GetStringFromName("alertDownloadsStart2"),

Просмотреть файл

@ -18,7 +18,6 @@ function openWindow(aParent, aURL, aTarget, aFeatures, aArgs) {
let argsArray = Cc["@mozilla.org/supports-array;1"].createInstance(Ci.nsISupportsArray);
let urlString = null;
let pinnedBool = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool);
let guestBool = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool);
let widthInt = Cc["@mozilla.org/supports-PRInt32;1"].createInstance(Ci.nsISupportsPRInt32);
let heightInt = Cc["@mozilla.org/supports-PRInt32;1"].createInstance(Ci.nsISupportsPRInt32);
@ -29,13 +28,11 @@ function openWindow(aParent, aURL, aTarget, aFeatures, aArgs) {
widthInt.data = "width" in aArgs ? aArgs.width : 1;
heightInt.data = "height" in aArgs ? aArgs.height : 1;
pinnedBool.data = "pinned" in aArgs ? aArgs.pinned : false;
guestBool.data = "guest" in aArgs ? aArgs["guest"] : false;
argsArray.AppendElement(urlString, false);
argsArray.AppendElement(widthInt, false);
argsArray.AppendElement(heightInt, false);
argsArray.AppendElement(pinnedBool, false);
argsArray.AppendElement(guestBool, false);
return Services.ww.openWindow(aParent, aURL, aTarget, aFeatures, argsArray);
}
@ -61,7 +58,6 @@ BrowserCLH.prototype = {
handle: function fs_handle(aCmdLine) {
let openURL = "about:home";
let pinned = false;
let guest = false;
let width = 1;
let height = 1;
@ -72,9 +68,6 @@ BrowserCLH.prototype = {
try {
pinned = aCmdLine.handleFlag("webapp", false);
} catch (e) { /* Optional */ }
try {
guest = aCmdLine.handleFlag("guest", false);
} catch (e) { /* Optional */ }
try {
width = aCmdLine.handleFlagWithParam("width", false);
@ -102,7 +95,6 @@ BrowserCLH.prototype = {
pinned: pinned,
width: width,
height: height,
guest: guest
};
// Make sure webapps do not have: locationbar, personalbar, menubar, statusbar, and toolbar

Просмотреть файл

@ -60,4 +60,4 @@ retrievalFailedTitle=#1 update failed;#1 updates failed
# example: Failed to retrieve updates for Foo, Bar, Baz
retrievalFailedMessage=Failed to retrieve update for %1$S;Failed to retrieve updates for %1$S
webappsDisabledInGuest=Installing apps is disabled in guest sessions
webappsDisabled=Installing apps is disabled

Просмотреть файл

@ -29,6 +29,9 @@ XPCOMUtils.defineLazyGetter(this, "Strings", function() {
return Services.strings.createBundle("chrome://browser/locale/webapp.properties");
});
XPCOMUtils.defineLazyServiceGetter(this, "ParentalControls",
"@mozilla.org/parental-controls-service;1", "nsIParentalControlsService");
/**
* Get the formatted plural form of a string. Escapes semicolons in arguments
* to provide to the formatter before formatting the string, then unescapes them
@ -89,8 +92,8 @@ this.WebappManager = {
},
_installApk: function(aMessage, aMessageManager) { return Task.spawn((function*() {
if (this.inGuestSession()) {
aMessage.error = Strings.GetStringFromName("webappsDisabledInGuest"),
if (!ParentalControls.isAllowed(ParentalControls.INSTALL_APPS)) {
aMessage.error = Strings.GetStringFromName("webappsDisabled"),
aMessageManager.sendAsyncMessage("Webapps:Install:Return:KO", aMessage);
return;
}
@ -277,10 +280,6 @@ this.WebappManager = {
}),
inGuestSession: function() {
return Services.wm.getMostRecentWindow("navigator:browser").BrowserApp.isGuest;
},
autoInstall: function(aData) {
debug("autoInstall " + aData.manifestURL);

Просмотреть файл

@ -11,9 +11,21 @@ interface nsIFile;
interface nsIInterfaceRequestor;
interface nsIArray;
[scriptable, uuid(871cf229-2b21-4f04-b24d-e08061f14815)]
[scriptable, uuid(b3585b2a-b4b3-4aa7-be92-b8ddaa6aec5f)]
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
const short VISIT_FILE_URLS = 4; // Opening file:/// urls
const short SHARE = 5; // Sharing
const short BOOKMARK = 6; // Creating bookmarks
const short ADD_CONTACT = 7; // Add contacts to the system database
const short SET_IMAGE = 8; // Setting images as wall paper
/**
* @returns true if the current user account has parental controls
* restrictions enabled.
@ -26,6 +38,15 @@ interface nsIParentalControlsService : nsISupports
*/
readonly attribute boolean blockFileDownloadsEnabled;
/**
* Check if the user can do the prescibed action for this uri.
*
* @param aAction Action being performed
* @param aUri The uri requesting this action
* @param aWindow The window generating this event.
*/
boolean isAllowed(in short aAction, [optional] in nsIURI aUri);
/**
* Request that blocked URI(s) be allowed through parental
* control filters. Returns true if the URI was successfully

Просмотреть файл

@ -14,7 +14,7 @@ nsParentalControlsService::nsParentalControlsService() :
mEnabled(false)
{
if (mozilla::AndroidBridge::HasEnv()) {
mEnabled = mozilla::widget::android::GeckoAppShell::IsUserRestricted();
mEnabled = mozilla::widget::android::RestrictedProfiles::IsUserRestricted();
}
}
@ -32,7 +32,11 @@ nsParentalControlsService::GetParentalControlsEnabled(bool *aResult)
NS_IMETHODIMP
nsParentalControlsService::GetBlockFileDownloadsEnabled(bool *aResult)
{
return NS_ERROR_NOT_AVAILABLE;
bool res;
IsAllowed(nsIParentalControlsService::DOWNLOAD, NULL, &res);
*aResult = res;
return NS_OK;
}
NS_IMETHODIMP
@ -65,3 +69,30 @@ nsParentalControlsService::RequestURIOverrides(nsIArray *aTargets,
{
return NS_ERROR_NOT_AVAILABLE;
}
NS_IMETHODIMP
nsParentalControlsService::IsAllowed(int16_t aAction,
nsIURI *aUri,
bool *_retval)
{
nsresult rv = NS_OK;
*_retval = true;
if (!mEnabled) {
return rv;
}
if (mozilla::AndroidBridge::HasEnv()) {
nsAutoCString url;
if (aUri) {
rv = aUri->GetSpec(url);
NS_ENSURE_SUCCESS(rv, rv);
}
*_retval = mozilla::widget::android::RestrictedProfiles::IsAllowed(aAction,
NS_ConvertUTF8toUTF16(url));
return rv;
}
return NS_ERROR_NOT_AVAILABLE;
}

Просмотреть файл

@ -65,3 +65,12 @@ nsParentalControlsService::RequestURIOverrides(nsIArray *aTargets,
{
return NS_ERROR_NOT_AVAILABLE;
}
NS_IMETHODIMP
nsParentalControlsService::IsAllowed(int16_t aAction,
nsIURI *aUri,
bool *_retval)
{
return NS_ERROR_NOT_AVAILABLE;
}

Просмотреть файл

@ -60,3 +60,11 @@ nsParentalControlsService::RequestURIOverrides(nsIArray *aTargets,
{
return NS_ERROR_NOT_AVAILABLE;
}
NS_IMETHODIMP
nsParentalControlsService::IsAllowed(int16_t aAction,
nsIURI *aUri,
bool *_retval)
{
return NS_ERROR_NOT_AVAILABLE;
}

Просмотреть файл

@ -331,3 +331,10 @@ nsParentalControlsService::LogFileDownload(bool blocked, nsIURI *aSource, nsIFil
gEventWrite(mProvider, &WPCEVENT_WEB_FILEDOWNLOAD, ARRAYSIZE(eventData), eventData);
}
NS_IMETHODIMP
nsParentalControlsService::IsAllowed(int16_t aAction,
nsIURI *aUri,
bool *_retval)
{
return NS_ERROR_NOT_AVAILABLE;
}

Просмотреть файл

@ -55,7 +55,6 @@ jmethodID GeckoAppShell::jGetScreenDepthWrapper = 0;
jmethodID GeckoAppShell::jGetScreenOrientationWrapper = 0;
jmethodID GeckoAppShell::jGetShowPasswordSetting = 0;
jmethodID GeckoAppShell::jGetSystemColoursWrapper = 0;
jmethodID GeckoAppShell::jGetUserRestrictions = 0;
jmethodID GeckoAppShell::jHandleGeckoMessageWrapper = 0;
jmethodID GeckoAppShell::jHandleUncaughtException = 0;
jmethodID GeckoAppShell::jHideProgressDialog = 0;
@ -63,7 +62,6 @@ jmethodID GeckoAppShell::jInitCameraWrapper = 0;
jmethodID GeckoAppShell::jIsNetworkLinkKnown = 0;
jmethodID GeckoAppShell::jIsNetworkLinkUp = 0;
jmethodID GeckoAppShell::jIsTablet = 0;
jmethodID GeckoAppShell::jIsUserRestricted = 0;
jmethodID GeckoAppShell::jKillAnyZombies = 0;
jmethodID GeckoAppShell::jLoadPluginClass = 0;
jmethodID GeckoAppShell::jLockScreenOrientation = 0;
@ -144,7 +142,6 @@ void GeckoAppShell::InitStubs(JNIEnv *jEnv) {
jGetScreenOrientationWrapper = getStaticMethod("getScreenOrientation", "()S");
jGetShowPasswordSetting = getStaticMethod("getShowPasswordSetting", "()Z");
jGetSystemColoursWrapper = getStaticMethod("getSystemColors", "()[I");
jGetUserRestrictions = getStaticMethod("getUserRestrictions", "()Ljava/lang/String;");
jHandleGeckoMessageWrapper = getStaticMethod("handleGeckoMessage", "(Lorg/mozilla/gecko/util/NativeJSContainer;)V");
jHandleUncaughtException = getStaticMethod("handleUncaughtException", "(Ljava/lang/Thread;Ljava/lang/Throwable;)V");
jHideProgressDialog = getStaticMethod("hideProgressDialog", "()V");
@ -152,7 +149,6 @@ void GeckoAppShell::InitStubs(JNIEnv *jEnv) {
jIsNetworkLinkKnown = getStaticMethod("isNetworkLinkKnown", "()Z");
jIsNetworkLinkUp = getStaticMethod("isNetworkLinkUp", "()Z");
jIsTablet = getStaticMethod("isTablet", "()Z");
jIsUserRestricted = getStaticMethod("isUserRestricted", "()Z");
jKillAnyZombies = getStaticMethod("killAnyZombies", "()V");
jLoadPluginClass = getStaticMethod("loadPluginClass", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Class;");
jLockScreenOrientation = getStaticMethod("lockScreenOrientation", "(I)V");
@ -787,19 +783,6 @@ jintArray GeckoAppShell::GetSystemColoursWrapper() {
return ret;
}
jstring GeckoAppShell::GetUserRestrictions() {
JNIEnv *env = AndroidBridge::GetJNIEnv();
if (env->PushLocalFrame(1) != 0) {
AndroidBridge::HandleUncaughtException(env);
MOZ_CRASH("Exception should have caused crash.");
}
jobject temp = env->CallStaticObjectMethod(mGeckoAppShellClass, jGetUserRestrictions);
AndroidBridge::HandleUncaughtException(env);
jstring ret = static_cast<jstring>(env->PopLocalFrame(temp));
return ret;
}
void GeckoAppShell::HandleGeckoMessageWrapper(jobject a0) {
JNIEnv *env = AndroidBridge::GetJNIEnv();
if (env->PushLocalFrame(1) != 0) {
@ -892,19 +875,6 @@ bool GeckoAppShell::IsTablet() {
return temp;
}
bool GeckoAppShell::IsUserRestricted() {
JNIEnv *env = AndroidBridge::GetJNIEnv();
if (env->PushLocalFrame(0) != 0) {
AndroidBridge::HandleUncaughtException(env);
MOZ_CRASH("Exception should have caused crash.");
}
bool temp = env->CallStaticBooleanMethod(mGeckoAppShellClass, jIsUserRestricted);
AndroidBridge::HandleUncaughtException(env);
env->PopLocalFrame(nullptr);
return temp;
}
void GeckoAppShell::KillAnyZombies() {
JNIEnv *env = AndroidBridge::GetJNIEnv();
if (env->PushLocalFrame(0) != 0) {
@ -1564,6 +1534,66 @@ void GeckoJavaSampler::UnpauseJavaProfiling() {
AndroidBridge::HandleUncaughtException(env);
env->PopLocalFrame(nullptr);
}
jclass RestrictedProfiles::mRestrictedProfilesClass = 0;
jmethodID RestrictedProfiles::jGetUserRestrictions = 0;
jmethodID RestrictedProfiles::jIsAllowed = 0;
jmethodID RestrictedProfiles::jIsUserRestricted = 0;
void RestrictedProfiles::InitStubs(JNIEnv *jEnv) {
initInit();
mRestrictedProfilesClass = getClassGlobalRef("org/mozilla/gecko/RestrictedProfiles");
jGetUserRestrictions = getStaticMethod("getUserRestrictions", "()Ljava/lang/String;");
jIsAllowed = getStaticMethod("isAllowed", "(ILjava/lang/String;)Z");
jIsUserRestricted = getStaticMethod("isUserRestricted", "()Z");
}
RestrictedProfiles* RestrictedProfiles::Wrap(jobject obj) {
JNIEnv *env = GetJNIForThread();
RestrictedProfiles* ret = new RestrictedProfiles(obj, env);
env->DeleteLocalRef(obj);
return ret;
}
jstring RestrictedProfiles::GetUserRestrictions() {
JNIEnv *env = AndroidBridge::GetJNIEnv();
if (env->PushLocalFrame(1) != 0) {
AndroidBridge::HandleUncaughtException(env);
MOZ_CRASH("Exception should have caused crash.");
}
jobject temp = env->CallStaticObjectMethod(mRestrictedProfilesClass, jGetUserRestrictions);
AndroidBridge::HandleUncaughtException(env);
jstring ret = static_cast<jstring>(env->PopLocalFrame(temp));
return ret;
}
bool RestrictedProfiles::IsAllowed(int32_t a0, const nsAString& a1) {
JNIEnv *env = AndroidBridge::GetJNIEnv();
if (env->PushLocalFrame(1) != 0) {
AndroidBridge::HandleUncaughtException(env);
MOZ_CRASH("Exception should have caused crash.");
}
jstring j1 = AndroidBridge::NewJavaString(env, a1);
bool temp = env->CallStaticBooleanMethod(mRestrictedProfilesClass, jIsAllowed, a0, j1);
AndroidBridge::HandleUncaughtException(env);
env->PopLocalFrame(nullptr);
return temp;
}
bool RestrictedProfiles::IsUserRestricted() {
JNIEnv *env = AndroidBridge::GetJNIEnv();
if (env->PushLocalFrame(0) != 0) {
AndroidBridge::HandleUncaughtException(env);
MOZ_CRASH("Exception should have caused crash.");
}
bool temp = env->CallStaticBooleanMethod(mRestrictedProfilesClass, jIsUserRestricted);
AndroidBridge::HandleUncaughtException(env);
env->PopLocalFrame(nullptr);
return temp;
}
jclass SurfaceBits::mSurfaceBitsClass = 0;
jmethodID SurfaceBits::jSurfaceBits = 0;
jfieldID SurfaceBits::jbuffer = 0;
@ -2545,6 +2575,7 @@ void InitStubs(JNIEnv *jEnv) {
GeckoAppShell::InitStubs(jEnv);
JavaDomKeyLocation::InitStubs(jEnv);
GeckoJavaSampler::InitStubs(jEnv);
RestrictedProfiles::InitStubs(jEnv);
SurfaceBits::InitStubs(jEnv);
ThumbnailHelper::InitStubs(jEnv);
DisplayPortMetrics::InitStubs(jEnv);

Просмотреть файл

@ -62,7 +62,6 @@ public:
static int16_t GetScreenOrientationWrapper();
static bool GetShowPasswordSetting();
static jintArray GetSystemColoursWrapper();
static jstring GetUserRestrictions();
static void HandleGeckoMessageWrapper(jobject a0);
static void HandleUncaughtException(jobject a0, jthrowable a1);
static void HideProgressDialog();
@ -70,7 +69,6 @@ public:
static bool IsNetworkLinkKnown();
static bool IsNetworkLinkUp();
static bool IsTablet();
static bool IsUserRestricted();
static void KillAnyZombies();
static jclass LoadPluginClass(const nsAString& a0, const nsAString& a1);
static void LockScreenOrientation(int32_t a0);
@ -150,7 +148,6 @@ protected:
static jmethodID jGetScreenOrientationWrapper;
static jmethodID jGetShowPasswordSetting;
static jmethodID jGetSystemColoursWrapper;
static jmethodID jGetUserRestrictions;
static jmethodID jHandleGeckoMessageWrapper;
static jmethodID jHandleUncaughtException;
static jmethodID jHideProgressDialog;
@ -158,7 +155,6 @@ protected:
static jmethodID jIsNetworkLinkKnown;
static jmethodID jIsNetworkLinkUp;
static jmethodID jIsTablet;
static jmethodID jIsUserRestricted;
static jmethodID jKillAnyZombies;
static jmethodID jLoadPluginClass;
static jmethodID jLockScreenOrientation;
@ -246,6 +242,22 @@ protected:
static jmethodID jUnpauseJavaProfiling;
};
class RestrictedProfiles : public AutoGlobalWrappedJavaObject {
public:
static void InitStubs(JNIEnv *jEnv);
static RestrictedProfiles* Wrap(jobject obj);
RestrictedProfiles(jobject obj, JNIEnv* env) : AutoGlobalWrappedJavaObject(obj, env) {};
static jstring GetUserRestrictions();
static bool IsAllowed(int32_t a0, const nsAString& a1);
static bool IsUserRestricted();
RestrictedProfiles() : AutoGlobalWrappedJavaObject() {};
protected:
static jclass mRestrictedProfilesClass;
static jmethodID jGetUserRestrictions;
static jmethodID jIsAllowed;
static jmethodID jIsUserRestricted;
};
class SurfaceBits : public AutoGlobalWrappedJavaObject {
public:
static void InitStubs(JNIEnv *jEnv);