PermissionRequest.java revision b2e56e34de371041a5e48d8fd2644e2727cc528e
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(long) grant()} or {@link #deny()} must be called in UI
26 * thread to respond to the request.
27 */
28public interface PermissionRequest {
29    /**
30     * Resource belongs to geolocation service.
31     * @hide - see b/14668406
32     */
33    public final static long RESOURCE_GEOLOCATION = 1 << 0;
34    /**
35     * Resource belongs to video capture device, like camera.
36     */
37    public final static long RESOURCE_VIDEO_CAPTURE = 1 << 1;
38    /**
39     * Resource belongs to audio capture device, like microphone.
40     */
41    public final static long RESOURCE_AUDIO_CAPTURE = 1 << 2;
42
43    /**
44     * @return the origin of web content which attempt to access the restricted
45     *         resources.
46     */
47    public Uri getOrigin();
48
49    /**
50     * @return a bit mask of resources the web content wants to access.
51     */
52    public long getResources();
53
54    /**
55     * Call this method to grant origin the permission to access the given resources.
56     * The granted permission is only valid for this WebView.
57     *
58     * @param resources the resources granted to be accessed by origin, to grant
59     *        request, the requested resources returned by {@link #getResources()}
60     *        must be equals or a subset of granted resources.
61     *        This parameter is designed to avoid granting permission by accident
62     *        especially when new resources are requested by web content.
63     */
64    public void grant(long resources);
65
66    /**
67     * Call this method to deny the request.
68     */
69    public void deny();
70}
71