summaryrefslogtreecommitdiffstats
path: root/mobile/android/base/java/org/mozilla/gecko/restrictions/GuestProfileConfiguration.java
blob: f9663ccf7eb162f403685095ecd07e30e127687c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* -*- 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.restrictions;

import android.net.Uri;

import java.util.Arrays;
import java.util.List;

/**
 * RestrictionConfiguration implementation for guest profiles.
 */
public class GuestProfileConfiguration implements RestrictionConfiguration {
    static List<Restrictable> DISABLED_FEATURES = Arrays.asList(
            Restrictable.DOWNLOAD,
            Restrictable.INSTALL_EXTENSION,
            Restrictable.INSTALL_APPS,
            Restrictable.BROWSE,
            Restrictable.SHARE,
            Restrictable.BOOKMARK,
            Restrictable.ADD_CONTACT,
            Restrictable.SET_IMAGE,
            Restrictable.MODIFY_ACCOUNTS,
            Restrictable.REMOTE_DEBUGGING,
            Restrictable.IMPORT_SETTINGS,
            Restrictable.BLOCK_LIST,
            Restrictable.DATA_CHOICES,
            Restrictable.DEFAULT_THEME
    );

    @SuppressWarnings("serial")
    private static final List<String> BANNED_SCHEMES = Arrays.asList(
            "file",
            "chrome",
            "resource",
            "jar",
            "wyciwyg"
    );

    private static final List<String> BANNED_URLS = Arrays.asList(
            "about:config",
            "about:addons"
    );

    @Override
    public boolean isAllowed(Restrictable restrictable) {
        return !DISABLED_FEATURES.contains(restrictable);
    }

    @Override
    public boolean canLoadUrl(String url) {
        // Null URLs are always permitted.
        if (url == null) {
            return true;
        }

        final Uri u = Uri.parse(url);
        final String scheme = u.getScheme();
        if (BANNED_SCHEMES.contains(scheme)) {
            return false;
        }

        url = url.toLowerCase();
        for (String banned : BANNED_URLS) {
            if (url.startsWith(banned)) {
                return false;
            }
        }

        return true;
    }

    @Override
    public boolean isRestricted() {
        return true;
    }

    @Override
    public void update() {}
}