Steve Block | 0ac031b | 2009-07-28 11:53:20 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.webkit; |
| 18 | |
Ignacio Solla | 451e338 | 2014-11-10 10:35:54 +0000 | [diff] [blame] | 19 | import android.annotation.SystemApi; |
| 20 | |
Steve Block | 0ac031b | 2009-07-28 11:53:20 +0100 | [diff] [blame] | 21 | import java.util.Set; |
| 22 | |
Steve Block | 0ac031b | 2009-07-28 11:53:20 +0100 | [diff] [blame] | 23 | /** |
Steve Block | 7351adf | 2011-11-30 15:52:32 +0000 | [diff] [blame] | 24 | * This class is used to manage permissions for the WebView's Geolocation |
| 25 | * JavaScript API. |
Steve Block | 57534f1 | 2009-11-19 12:29:47 +0000 | [diff] [blame] | 26 | * |
Steve Block | 7351adf | 2011-11-30 15:52:32 +0000 | [diff] [blame] | 27 | * 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 Block | 57534f1 | 2009-11-19 12:29:47 +0000 | [diff] [blame] | 30 | * |
Steve Block | 7351adf | 2011-11-30 15:52:32 +0000 | [diff] [blame] | 31 | * 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 Block | 57534f1 | 2009-11-19 12:29:47 +0000 | [diff] [blame] | 34 | * |
Steve Block | 7351adf | 2011-11-30 15:52:32 +0000 | [diff] [blame] | 35 | * 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 Block | 0ac031b | 2009-07-28 11:53:20 +0100 | [diff] [blame] | 42 | */ |
Steve Block | 7351adf | 2011-11-30 15:52:32 +0000 | [diff] [blame] | 43 | // 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 Dixon | 939e504 | 2012-04-12 21:21:07 +0100 | [diff] [blame] | 46 | public class GeolocationPermissions { |
Steve Block | 4faee09 | 2009-07-28 18:20:50 +0100 | [diff] [blame] | 47 | /** |
Steve Block | 7351adf | 2011-11-30 15:52:32 +0000 | [diff] [blame] | 48 | * A callback interface used by the host application to set the Geolocation |
| 49 | * permission state for an origin. |
Steve Block | 4faee09 | 2009-07-28 18:20:50 +0100 | [diff] [blame] | 50 | */ |
| 51 | public interface Callback { |
Steve Block | 7351adf | 2011-11-30 15:52:32 +0000 | [diff] [blame] | 52 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 53 | * 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 Block | 7351adf | 2011-11-30 15:52:32 +0000 | [diff] [blame] | 59 | * lifetime of a page currently being displayed by a |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 60 | * WebView |
Steve Block | 7351adf | 2011-11-30 15:52:32 +0000 | [diff] [blame] | 61 | */ |
| 62 | public void invoke(String origin, boolean allow, boolean retain); |
Steve Block | 4faee09 | 2009-07-28 18:20:50 +0100 | [diff] [blame] | 63 | }; |
| 64 | |
Steve Block | 0ac031b | 2009-07-28 11:53:20 +0100 | [diff] [blame] | 65 | /** |
Kristian Monsen | 51f5363 | 2012-11-30 15:53:08 -0800 | [diff] [blame] | 66 | * Gets the singleton instance of this class. This method cannot be |
| 67 | * called before the application instantiates a {@link WebView} instance. |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 68 | * |
| 69 | * @return the singleton {@link GeolocationPermissions} instance |
Steve Block | 0ac031b | 2009-07-28 11:53:20 +0100 | [diff] [blame] | 70 | */ |
| 71 | public static GeolocationPermissions getInstance() { |
Jonathan Dixon | d3101b1 | 2012-04-12 20:51:51 +0100 | [diff] [blame] | 72 | return WebViewFactory.getProvider().getGeolocationPermissions(); |
Nicolas Roard | 6c24b4d | 2009-09-22 18:44:52 +0100 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 76 | * 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 Block | 7351adf | 2011-11-30 15:52:32 +0000 | [diff] [blame] | 79 | * 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 Block | 0ac031b | 2009-07-28 11:53:20 +0100 | [diff] [blame] | 84 | */ |
Steve Block | 7351adf | 2011-11-30 15:52:32 +0000 | [diff] [blame] | 85 | // 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 Block | 57534f1 | 2009-11-19 12:29:47 +0000 | [diff] [blame] | 89 | public void getOrigins(ValueCallback<Set<String> > callback) { |
Jonathan Dixon | d3101b1 | 2012-04-12 20:51:51 +0100 | [diff] [blame] | 90 | // Must be a no-op for backward compatibility: see the hidden constructor for reason. |
Steve Block | 0ac031b | 2009-07-28 11:53:20 +0100 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 94 | * 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 Block | 7351adf | 2011-11-30 15:52:32 +0000 | [diff] [blame] | 98 | * 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 Block | 0ac031b | 2009-07-28 11:53:20 +0100 | [diff] [blame] | 103 | */ |
Nicolas Roard | 6c24b4d | 2009-09-22 18:44:52 +0100 | [diff] [blame] | 104 | public void getAllowed(String origin, ValueCallback<Boolean> callback) { |
Jonathan Dixon | d3101b1 | 2012-04-12 20:51:51 +0100 | [diff] [blame] | 105 | // Must be a no-op for backward compatibility: see the hidden constructor for reason. |
Steve Block | 0ac031b | 2009-07-28 11:53:20 +0100 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 109 | * Clears the Geolocation permission state for the specified origin. |
| 110 | * |
| 111 | * @param origin the origin for which Geolocation permissions are cleared |
Steve Block | 0ac031b | 2009-07-28 11:53:20 +0100 | [diff] [blame] | 112 | */ |
| 113 | public void clear(String origin) { |
Jonathan Dixon | d3101b1 | 2012-04-12 20:51:51 +0100 | [diff] [blame] | 114 | // Must be a no-op for backward compatibility: see the hidden constructor for reason. |
Steve Block | d875ce6 | 2009-08-24 11:31:18 +0100 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 118 | * Allows the specified origin to use the Geolocation API. |
| 119 | * |
| 120 | * @param origin the origin for which Geolocation API use is allowed |
Steve Block | d875ce6 | 2009-08-24 11:31:18 +0100 | [diff] [blame] | 121 | */ |
| 122 | public void allow(String origin) { |
Jonathan Dixon | d3101b1 | 2012-04-12 20:51:51 +0100 | [diff] [blame] | 123 | // Must be a no-op for backward compatibility: see the hidden constructor for reason. |
Steve Block | 0ac031b | 2009-07-28 11:53:20 +0100 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 127 | * Clears the Geolocation permission state for all origins. |
Steve Block | 0ac031b | 2009-07-28 11:53:20 +0100 | [diff] [blame] | 128 | */ |
| 129 | public void clearAll() { |
Jonathan Dixon | d3101b1 | 2012-04-12 20:51:51 +0100 | [diff] [blame] | 130 | // Must be a no-op for backward compatibility: see the hidden constructor for reason. |
Steve Block | 0ac031b | 2009-07-28 11:53:20 +0100 | [diff] [blame] | 131 | } |
| 132 | |
Jonathan Dixon | a3dc86e | 2012-03-28 12:27:36 +0100 | [diff] [blame] | 133 | /** |
| 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 Dixon | d3101b1 | 2012-04-12 20:51:51 +0100 | [diff] [blame] | 139 | * @hide Only for use by WebViewProvider implementations |
Jonathan Dixon | a3dc86e | 2012-03-28 12:27:36 +0100 | [diff] [blame] | 140 | */ |
Ignacio Solla | 451e338 | 2014-11-10 10:35:54 +0000 | [diff] [blame] | 141 | @SystemApi |
Jonathan Dixon | a3dc86e | 2012-03-28 12:27:36 +0100 | [diff] [blame] | 142 | public GeolocationPermissions() {} |
Steve Block | 0ac031b | 2009-07-28 11:53:20 +0100 | [diff] [blame] | 143 | } |