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 class defines a permission request and is used when web content
23 * requests access to protected resources. The permission request related events
24 * are delivered via {@link WebChromeClient#onPermissionRequest} and
25 * {@link WebChromeClient#onPermissionRequestCanceled}.
26 *
27 * Either {@link #grant(String[]) grant()} or {@link #deny()} must be called in UI
28 * thread to respond to the request.
29 */
30public abstract class PermissionRequest {
31    /**
32     * Resource belongs to video capture device, like camera.
33     */
34    public final static String RESOURCE_VIDEO_CAPTURE = "android.webkit.resource.VIDEO_CAPTURE";
35    /**
36     * Resource belongs to audio capture device, like microphone.
37     */
38    public final static String RESOURCE_AUDIO_CAPTURE = "android.webkit.resource.AUDIO_CAPTURE";
39    /**
40     * Resource belongs to protected media identifier.
41     * After the user grants this resource, the origin can use EME APIs to generate the license
42     * requests.
43     */
44    public final static String RESOURCE_PROTECTED_MEDIA_ID =
45            "android.webkit.resource.PROTECTED_MEDIA_ID";
46
47    /**
48     * Call this method to get the origin of the web page which is trying to access
49     * the restricted resources.
50     *
51     * @return the origin of web content which attempt to access the restricted
52     *         resources.
53     */
54    public abstract Uri getOrigin();
55
56    /**
57     * Call this method to get the resources the web page is trying to access.
58     *
59     * @return the array of resources the web content wants to access.
60     */
61    public abstract String[] getResources();
62
63    /**
64     * Call this method to grant origin the permission to access the given resources.
65     * The granted permission is only valid for this WebView.
66     *
67     * @param resources the resources granted to be accessed by origin, to grant
68     *        request, the requested resources returned by {@link #getResources()}
69     *        must be equals or a subset of granted resources.
70     *        This parameter is designed to avoid granting permission by accident
71     *        especially when new resources are requested by web content.
72     */
73    public abstract void grant(String[] resources);
74
75    /**
76     * Call this method to deny the request.
77     */
78    public abstract void deny();
79}
80