blob: 7187f221c77dc3b8747293354e75f7d47dd5257b [file] [log] [blame]
Steve Block0ac031b2009-07-28 11:53:20 +01001/*
2 * Copyright (C) 2009 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
Ignacio Solla451e3382014-11-10 10:35:54 +000019import android.annotation.SystemApi;
20
Steve Block0ac031b2009-07-28 11:53:20 +010021import java.util.Set;
22
Steve Block0ac031b2009-07-28 11:53:20 +010023/**
Steve Block7351adf2011-11-30 15:52:32 +000024 * This class is used to manage permissions for the WebView's Geolocation
25 * JavaScript API.
Steve Block57534f12009-11-19 12:29:47 +000026 *
Steve Block7351adf2011-11-30 15:52:32 +000027 * Geolocation permissions are applied to an origin, which consists of the
28 * host, scheme and port of a URI. In order for web content to use the
29 * Geolocation API, permission must be granted for that content's origin.
Steve Block57534f12009-11-19 12:29:47 +000030 *
Steve Block7351adf2011-11-30 15:52:32 +000031 * This class stores Geolocation permissions. An origin's permission state can
32 * be either allowed or denied. This class uses Strings to represent
33 * an origin.
Steve Block57534f12009-11-19 12:29:47 +000034 *
Steve Block7351adf2011-11-30 15:52:32 +000035 * When an origin attempts to use the Geolocation API, but no permission state
36 * is currently set for that origin,
37 * {@link WebChromeClient#onGeolocationPermissionsShowPrompt(String,GeolocationPermissions.Callback) WebChromeClient.onGeolocationPermissionsShowPrompt()}
38 * is called. This allows the permission state to be set for that origin.
39 *
40 * The methods of this class can be used to modify and interrogate the stored
41 * Geolocation permissions at any time.
Steve Block0ac031b2009-07-28 11:53:20 +010042 */
Steve Block7351adf2011-11-30 15:52:32 +000043// Within WebKit, Geolocation permissions may be applied either temporarily
44// (for the duration of the page) or permanently. This class deals only with
45// permanent permissions.
Jonathan Dixon939e5042012-04-12 21:21:07 +010046public class GeolocationPermissions {
Steve Block4faee092009-07-28 18:20:50 +010047 /**
Steve Block7351adf2011-11-30 15:52:32 +000048 * A callback interface used by the host application to set the Geolocation
49 * permission state for an origin.
Steve Block4faee092009-07-28 18:20:50 +010050 */
51 public interface Callback {
Steve Block7351adf2011-11-30 15:52:32 +000052 /**
Steve Block4e584df2012-04-24 23:12:47 +010053 * Sets the Geolocation permission state for the supplied origin.
54 *
55 * @param origin the origin for which permissions are set
56 * @param allow whether or not the origin should be allowed to use the
57 * Geolocation API
58 * @param retain whether the permission should be retained beyond the
Steve Block7351adf2011-11-30 15:52:32 +000059 * lifetime of a page currently being displayed by a
Steve Block4e584df2012-04-24 23:12:47 +010060 * WebView
Steve Block7351adf2011-11-30 15:52:32 +000061 */
62 public void invoke(String origin, boolean allow, boolean retain);
Steve Block4faee092009-07-28 18:20:50 +010063 };
64
Steve Block0ac031b2009-07-28 11:53:20 +010065 /**
Kristian Monsen51f53632012-11-30 15:53:08 -080066 * Gets the singleton instance of this class. This method cannot be
67 * called before the application instantiates a {@link WebView} instance.
Steve Block4e584df2012-04-24 23:12:47 +010068 *
69 * @return the singleton {@link GeolocationPermissions} instance
Steve Block0ac031b2009-07-28 11:53:20 +010070 */
71 public static GeolocationPermissions getInstance() {
Jonathan Dixond3101b12012-04-12 20:51:51 +010072 return WebViewFactory.getProvider().getGeolocationPermissions();
Nicolas Roard6c24b4d2009-09-22 18:44:52 +010073 }
74
75 /**
Steve Block4e584df2012-04-24 23:12:47 +010076 * Gets the set of origins for which Geolocation permissions are stored.
77 *
78 * @param callback a {@link ValueCallback} to receive the result of this
Steve Block7351adf2011-11-30 15:52:32 +000079 * request. This object's
80 * {@link ValueCallback#onReceiveValue(T) onReceiveValue()}
81 * method will be invoked asynchronously with a set of
82 * Strings containing the origins for which Geolocation
83 * permissions are stored.
Steve Block0ac031b2009-07-28 11:53:20 +010084 */
Steve Block7351adf2011-11-30 15:52:32 +000085 // Note that we represent the origins as strings. These are created using
86 // WebCore::SecurityOrigin::toString(). As long as all 'HTML 5 modules'
87 // (Database, Geolocation etc) do so, it's safe to match up origins based
88 // on this string.
Steve Block57534f12009-11-19 12:29:47 +000089 public void getOrigins(ValueCallback<Set<String> > callback) {
Jonathan Dixond3101b12012-04-12 20:51:51 +010090 // Must be a no-op for backward compatibility: see the hidden constructor for reason.
Steve Block0ac031b2009-07-28 11:53:20 +010091 }
92
93 /**
Steve Block4e584df2012-04-24 23:12:47 +010094 * Gets the Geolocation permission state for the specified origin.
95 *
96 * @param origin the origin for which Geolocation permission is requested
97 * @param callback a {@link ValueCallback} to receive the result of this
Steve Block7351adf2011-11-30 15:52:32 +000098 * request. This object's
99 * {@link ValueCallback#onReceiveValue(T) onReceiveValue()}
100 * method will be invoked asynchronously with a boolean
101 * indicating whether or not the origin can use the
102 * Geolocation API.
Steve Block0ac031b2009-07-28 11:53:20 +0100103 */
Nicolas Roard6c24b4d2009-09-22 18:44:52 +0100104 public void getAllowed(String origin, ValueCallback<Boolean> callback) {
Jonathan Dixond3101b12012-04-12 20:51:51 +0100105 // Must be a no-op for backward compatibility: see the hidden constructor for reason.
Steve Block0ac031b2009-07-28 11:53:20 +0100106 }
107
108 /**
Steve Block4e584df2012-04-24 23:12:47 +0100109 * Clears the Geolocation permission state for the specified origin.
110 *
111 * @param origin the origin for which Geolocation permissions are cleared
Steve Block0ac031b2009-07-28 11:53:20 +0100112 */
113 public void clear(String origin) {
Jonathan Dixond3101b12012-04-12 20:51:51 +0100114 // Must be a no-op for backward compatibility: see the hidden constructor for reason.
Steve Blockd875ce62009-08-24 11:31:18 +0100115 }
116
117 /**
Steve Block4e584df2012-04-24 23:12:47 +0100118 * Allows the specified origin to use the Geolocation API.
119 *
120 * @param origin the origin for which Geolocation API use is allowed
Steve Blockd875ce62009-08-24 11:31:18 +0100121 */
122 public void allow(String origin) {
Jonathan Dixond3101b12012-04-12 20:51:51 +0100123 // Must be a no-op for backward compatibility: see the hidden constructor for reason.
Steve Block0ac031b2009-07-28 11:53:20 +0100124 }
125
126 /**
Steve Block4e584df2012-04-24 23:12:47 +0100127 * Clears the Geolocation permission state for all origins.
Steve Block0ac031b2009-07-28 11:53:20 +0100128 */
129 public void clearAll() {
Jonathan Dixond3101b12012-04-12 20:51:51 +0100130 // Must be a no-op for backward compatibility: see the hidden constructor for reason.
Steve Block0ac031b2009-07-28 11:53:20 +0100131 }
132
Jonathan Dixona3dc86e2012-03-28 12:27:36 +0100133 /**
134 * This class should not be instantiated directly, applications must only use
135 * {@link #getInstance()} to obtain the instance.
136 * Note this constructor was erroneously public and published in SDK levels prior to 16, but
137 * applications using it would receive a non-functional instance of this class (there was no
138 * way to call createHandler() and createUIHandler(), so it would not work).
Jonathan Dixond3101b12012-04-12 20:51:51 +0100139 * @hide Only for use by WebViewProvider implementations
Jonathan Dixona3dc86e2012-03-28 12:27:36 +0100140 */
Ignacio Solla451e3382014-11-10 10:35:54 +0000141 @SystemApi
Jonathan Dixona3dc86e2012-03-28 12:27:36 +0100142 public GeolocationPermissions() {}
Steve Block0ac031b2009-07-28 11:53:20 +0100143}