PermissionRequest.java revision 2871febb19c02c2d11c0aa3835e884361e60c580
1/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.webkit;
18
19import android.net.Uri;
20
21/**
22 * This interface defines a permission request and is used when web content
23 * requests access to protected resources.
24 *
25 * Either {@link #grant(String[]) grant()} or {@link #deny()} must be called in UI
26 * thread to respond to the request.
27 */
28public abstract class PermissionRequest {
29    /**
30     * Resource belongs to video capture device, like camera.
31     */
32    public final static String RESOURCE_VIDEO_CAPTURE = "android.webkit.resource.VIDEO_CAPTURE";
33    /**
34     * Resource belongs to audio capture device, like microphone.
35     */
36    public final static String RESOURCE_AUDIO_CAPTURE = "android.webkit.resource.AUDIO_CAPTURE";
37    /**
38     * Resource belongs to protected media identifier.
39     * After the user grants this resource, the origin can use EME APIs to generate the license
40     * requests.
41     */
42    public final static String RESOURCE_PROTECTED_MEDIA_ID =
43            "android.webkit.resource.PROTECTED_MEDIA_ID";
44
45    /**
46     * Call this method to get the origin of the web page which is trying to access
47     * the restricted resources.
48     *
49     * @return the origin of web content which attempt to access the restricted
50     *         resources.
51     */
52    public abstract Uri getOrigin();
53
54    /**
55     * Call this method to get the resources the web page is trying to access.
56     *
57     * @return the array of resources the web content wants to access.
58     */
59    public abstract String[] getResources();
60
61    /**
62     * Call this method to grant origin the permission to access the given resources.
63     * The granted permission is only valid for this WebView.
64     *
65     * @param resources the resources granted to be accessed by origin, to grant
66     *        request, the requested resources returned by {@link #getResources()}
67     *        must be equals or a subset of granted resources.
68     *        This parameter is designed to avoid granting permission by accident
69     *        especially when new resources are requested by web content.
70     */
71    public abstract void grant(String[] resources);
72
73    /**
74     * Call this method to deny the request.
75     */
76    public abstract void deny();
77}
78