10ac031b3d29c6de90895c875991585812dc7388fSteve Block/*
20ac031b3d29c6de90895c875991585812dc7388fSteve Block * Copyright (C) 2009 The Android Open Source Project
30ac031b3d29c6de90895c875991585812dc7388fSteve Block *
40ac031b3d29c6de90895c875991585812dc7388fSteve Block * Licensed under the Apache License, Version 2.0 (the "License");
50ac031b3d29c6de90895c875991585812dc7388fSteve Block * you may not use this file except in compliance with the License.
60ac031b3d29c6de90895c875991585812dc7388fSteve Block * You may obtain a copy of the License at
70ac031b3d29c6de90895c875991585812dc7388fSteve Block *
80ac031b3d29c6de90895c875991585812dc7388fSteve Block *      http://www.apache.org/licenses/LICENSE-2.0
90ac031b3d29c6de90895c875991585812dc7388fSteve Block *
100ac031b3d29c6de90895c875991585812dc7388fSteve Block * Unless required by applicable law or agreed to in writing, software
110ac031b3d29c6de90895c875991585812dc7388fSteve Block * distributed under the License is distributed on an "AS IS" BASIS,
120ac031b3d29c6de90895c875991585812dc7388fSteve Block * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
130ac031b3d29c6de90895c875991585812dc7388fSteve Block * See the License for the specific language governing permissions and
140ac031b3d29c6de90895c875991585812dc7388fSteve Block * limitations under the License.
150ac031b3d29c6de90895c875991585812dc7388fSteve Block */
160ac031b3d29c6de90895c875991585812dc7388fSteve Block
170ac031b3d29c6de90895c875991585812dc7388fSteve Blockpackage android.webkit;
180ac031b3d29c6de90895c875991585812dc7388fSteve Block
19451e338c51e8c45efc0d21536dfae6f78f6d5e06Ignacio Sollaimport android.annotation.SystemApi;
20451e338c51e8c45efc0d21536dfae6f78f6d5e06Ignacio Solla
210ac031b3d29c6de90895c875991585812dc7388fSteve Blockimport java.util.Set;
220ac031b3d29c6de90895c875991585812dc7388fSteve Block
230ac031b3d29c6de90895c875991585812dc7388fSteve Block/**
247351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block * This class is used to manage permissions for the WebView's Geolocation
257351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block * JavaScript API.
2657534f1b9f52cea094e8197d1ca40f0d2f68cc66Steve Block *
277351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block * Geolocation permissions are applied to an origin, which consists of the
287351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block * host, scheme and port of a URI. In order for web content to use the
297351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block * Geolocation API, permission must be granted for that content's origin.
3057534f1b9f52cea094e8197d1ca40f0d2f68cc66Steve Block *
317351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block * This class stores Geolocation permissions. An origin's permission state can
327351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block * be either allowed or denied. This class uses Strings to represent
337351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block * an origin.
3457534f1b9f52cea094e8197d1ca40f0d2f68cc66Steve Block *
357351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block * When an origin attempts to use the Geolocation API, but no permission state
367351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block * is currently set for that origin,
377351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block * {@link WebChromeClient#onGeolocationPermissionsShowPrompt(String,GeolocationPermissions.Callback) WebChromeClient.onGeolocationPermissionsShowPrompt()}
387351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block * is called. This allows the permission state to be set for that origin.
397351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block *
407351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block * The methods of this class can be used to modify and interrogate the stored
417351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block * Geolocation permissions at any time.
420ac031b3d29c6de90895c875991585812dc7388fSteve Block */
437351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block// Within WebKit, Geolocation permissions may be applied either temporarily
447351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block// (for the duration of the page) or permanently. This class deals only with
457351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block// permanent permissions.
46939e5040b51539be561db1d18dec18196f201f5cJonathan Dixonpublic class GeolocationPermissions {
474faee09c422a70439129e9fb40dd82f03d42c98dSteve Block    /**
487351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block     * A callback interface used by the host application to set the Geolocation
497351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block     * permission state for an origin.
504faee09c422a70439129e9fb40dd82f03d42c98dSteve Block     */
514faee09c422a70439129e9fb40dd82f03d42c98dSteve Block    public interface Callback {
527351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block        /**
534e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block         * Sets the Geolocation permission state for the supplied origin.
544e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block         *
554e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block         * @param origin the origin for which permissions are set
564e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block         * @param allow whether or not the origin should be allowed to use the
574e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block         *              Geolocation API
584e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block         * @param retain whether the permission should be retained beyond the
597351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block         *               lifetime of a page currently being displayed by a
604e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block         *               WebView
617351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block         */
627351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block        public void invoke(String origin, boolean allow, boolean retain);
634faee09c422a70439129e9fb40dd82f03d42c98dSteve Block    };
644faee09c422a70439129e9fb40dd82f03d42c98dSteve Block
650ac031b3d29c6de90895c875991585812dc7388fSteve Block    /**
6651f536388e331fbe8348f4aac64d8c991d90acc1Kristian Monsen     * Gets the singleton instance of this class. This method cannot be
6751f536388e331fbe8348f4aac64d8c991d90acc1Kristian Monsen     * called before the application instantiates a {@link WebView} instance.
684e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     *
694e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     * @return the singleton {@link GeolocationPermissions} instance
700ac031b3d29c6de90895c875991585812dc7388fSteve Block     */
710ac031b3d29c6de90895c875991585812dc7388fSteve Block    public static GeolocationPermissions getInstance() {
72d3101b1d300f5942fdb7dfa323dc8830c4edc007Jonathan Dixon      return WebViewFactory.getProvider().getGeolocationPermissions();
736c24b4d10223cb522e6bdbf0e334f61e672f4366Nicolas Roard    }
746c24b4d10223cb522e6bdbf0e334f61e672f4366Nicolas Roard
756c24b4d10223cb522e6bdbf0e334f61e672f4366Nicolas Roard    /**
764e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     * Gets the set of origins for which Geolocation permissions are stored.
774e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     *
784e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     * @param callback a {@link ValueCallback} to receive the result of this
797351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block     *                 request. This object's
807351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block     *                 {@link ValueCallback#onReceiveValue(T) onReceiveValue()}
817351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block     *                 method will be invoked asynchronously with a set of
827351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block     *                 Strings containing the origins for which Geolocation
837351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block     *                 permissions are stored.
840ac031b3d29c6de90895c875991585812dc7388fSteve Block     */
857351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block    // Note that we represent the origins as strings. These are created using
867351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block    // WebCore::SecurityOrigin::toString(). As long as all 'HTML 5 modules'
877351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block    // (Database, Geolocation etc) do so, it's safe to match up origins based
887351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block    // on this string.
8957534f1b9f52cea094e8197d1ca40f0d2f68cc66Steve Block    public void getOrigins(ValueCallback<Set<String> > callback) {
90d3101b1d300f5942fdb7dfa323dc8830c4edc007Jonathan Dixon        // Must be a no-op for backward compatibility: see the hidden constructor for reason.
910ac031b3d29c6de90895c875991585812dc7388fSteve Block    }
920ac031b3d29c6de90895c875991585812dc7388fSteve Block
930ac031b3d29c6de90895c875991585812dc7388fSteve Block    /**
944e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     * Gets the Geolocation permission state for the specified origin.
954e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     *
964e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     * @param origin the origin for which Geolocation permission is requested
974e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     * @param callback a {@link ValueCallback} to receive the result of this
987351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block     *                 request. This object's
997351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block     *                 {@link ValueCallback#onReceiveValue(T) onReceiveValue()}
1007351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block     *                 method will be invoked asynchronously with a boolean
1017351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block     *                 indicating whether or not the origin can use the
1027351adf76a97b07bb2d777c56e78752cb7834bb0Steve Block     *                 Geolocation API.
1030ac031b3d29c6de90895c875991585812dc7388fSteve Block     */
1046c24b4d10223cb522e6bdbf0e334f61e672f4366Nicolas Roard    public void getAllowed(String origin, ValueCallback<Boolean> callback) {
105d3101b1d300f5942fdb7dfa323dc8830c4edc007Jonathan Dixon        // Must be a no-op for backward compatibility: see the hidden constructor for reason.
1060ac031b3d29c6de90895c875991585812dc7388fSteve Block    }
1070ac031b3d29c6de90895c875991585812dc7388fSteve Block
1080ac031b3d29c6de90895c875991585812dc7388fSteve Block    /**
1094e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     * Clears the Geolocation permission state for the specified origin.
1104e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     *
1114e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     * @param origin the origin for which Geolocation permissions are cleared
1120ac031b3d29c6de90895c875991585812dc7388fSteve Block     */
1130ac031b3d29c6de90895c875991585812dc7388fSteve Block    public void clear(String origin) {
114d3101b1d300f5942fdb7dfa323dc8830c4edc007Jonathan Dixon        // Must be a no-op for backward compatibility: see the hidden constructor for reason.
115d875ce6dac3c2e9a671c121c80b40d2536cbb2afSteve Block    }
116d875ce6dac3c2e9a671c121c80b40d2536cbb2afSteve Block
117d875ce6dac3c2e9a671c121c80b40d2536cbb2afSteve Block    /**
1184e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     * Allows the specified origin to use the Geolocation API.
1194e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     *
1204e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     * @param origin the origin for which Geolocation API use is allowed
121d875ce6dac3c2e9a671c121c80b40d2536cbb2afSteve Block     */
122d875ce6dac3c2e9a671c121c80b40d2536cbb2afSteve Block    public void allow(String origin) {
123d3101b1d300f5942fdb7dfa323dc8830c4edc007Jonathan Dixon        // Must be a no-op for backward compatibility: see the hidden constructor for reason.
1240ac031b3d29c6de90895c875991585812dc7388fSteve Block    }
1250ac031b3d29c6de90895c875991585812dc7388fSteve Block
1260ac031b3d29c6de90895c875991585812dc7388fSteve Block    /**
1274e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     * Clears the Geolocation permission state for all origins.
1280ac031b3d29c6de90895c875991585812dc7388fSteve Block     */
1290ac031b3d29c6de90895c875991585812dc7388fSteve Block    public void clearAll() {
130d3101b1d300f5942fdb7dfa323dc8830c4edc007Jonathan Dixon        // Must be a no-op for backward compatibility: see the hidden constructor for reason.
1310ac031b3d29c6de90895c875991585812dc7388fSteve Block    }
1320ac031b3d29c6de90895c875991585812dc7388fSteve Block
133a3dc86e637873be115e68be50bd1b281beff7994Jonathan Dixon    /**
134a3dc86e637873be115e68be50bd1b281beff7994Jonathan Dixon     * This class should not be instantiated directly, applications must only use
135a3dc86e637873be115e68be50bd1b281beff7994Jonathan Dixon     * {@link #getInstance()} to obtain the instance.
136a3dc86e637873be115e68be50bd1b281beff7994Jonathan Dixon     * Note this constructor was erroneously public and published in SDK levels prior to 16, but
137a3dc86e637873be115e68be50bd1b281beff7994Jonathan Dixon     * applications using it would receive a non-functional instance of this class (there was no
138a3dc86e637873be115e68be50bd1b281beff7994Jonathan Dixon     * way to call createHandler() and createUIHandler(), so it would not work).
139d3101b1d300f5942fdb7dfa323dc8830c4edc007Jonathan Dixon     * @hide Only for use by WebViewProvider implementations
140a3dc86e637873be115e68be50bd1b281beff7994Jonathan Dixon     */
141451e338c51e8c45efc0d21536dfae6f78f6d5e06Ignacio Solla    @SystemApi
142a3dc86e637873be115e68be50bd1b281beff7994Jonathan Dixon    public GeolocationPermissions() {}
1430ac031b3d29c6de90895c875991585812dc7388fSteve Block}
144