2 * Copyright 2009, The Android Open Source Project
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef GeolocationPermissions_h
27 #define GeolocationPermissions_h
29 #include "PlatformString.h"
30 // We must include this before before HashMap.h, as it provides specalizations
31 // for String hash types instantiated there.
32 #include "StringHash.h"
37 #include "wtf/RefCounted.h"
48 // The GeolocationPermissions class manages permissions for the browser.
49 // Each instance handles permissions for a given main frame. The class
50 // enforces the following policy.
51 // - Non-remembered permissions last for the dureation of the main frame.
52 // - Remembered permissions last indefinitely.
53 // - All permissions are shared between child frames of a main frame.
54 // - Only remembered permissions are shared between main frames.
55 // - Remembered permissions are made available for use in the browser
57 class GeolocationPermissions : public RefCounted<GeolocationPermissions> {
59 // Creates the GeolocationPermissions object to manage permissions for
60 // the specified main frame (i.e. tab). The WebViewCore is used to
61 // communicate with the browser to display UI.
62 GeolocationPermissions(WebViewCore* webViewCore, WebCore::Frame* mainFrame);
63 virtual ~GeolocationPermissions();
65 // Queries the permission state for the specified frame. If the
66 // permission state has not yet been set, prompts the user. Once the
67 // permission state has been determined, asynchronously calls back to
68 // the Geolocation objects in all frames in this WebView that are from
69 // the same origin as the requesting frame.
70 void queryPermissionState(WebCore::Frame* frame);
72 // Provides this object the given permission state from the user. The
73 // new permission state is recorded and will trigger callbacks to
74 // geolocation objects as described above. If any other permission
75 // requests are queued, the next is started.
76 void providePermissionState(WebCore::String origin, bool allow, bool remember);
78 // Clears the temporary permission state and any pending requests. Used
79 // when the main frame is refreshed or navigated to a new URL.
80 void resetTemporaryPermissionStates();
82 // Static methods for use from Java. These are used to interact with the
83 // browser settings menu and to update the permanent permissions when
84 // system settings are changed.
85 typedef HashSet<WebCore::String> OriginSet;
86 static OriginSet getOrigins();
87 static bool getAllowed(WebCore::String origin);
88 static void clear(WebCore::String origin);
89 static void allow(WebCore::String origin);
90 static void clearAll();
91 static void setAlwaysDeny(bool deny);
93 static void setDatabasePath(WebCore::String path);
96 // Records the permission state for the specified origin.
97 void recordPermissionState(WebCore::String origin, bool allow, bool remember);
99 // Used to make an asynchronous callback to the Geolocation objects.
100 void makeAsynchronousCallbackToGeolocation(WebCore::String origin, bool allow);
101 void timerFired(WebCore::Timer<GeolocationPermissions>* timer);
103 // Calls back to the Geolocation objects in all frames from the
104 // specified origin. There may be no such objects, as the frames using
105 // Geolocation from the specified origin may no longer use Geolocation,
106 // or may have been navigated to a different origin..
107 void maybeCallbackFrames(WebCore::String origin, bool allow);
109 // Cancels pending permission requests for the specified origin in
110 // other main frames (ie browser tabs). This is used when the user
111 // specifies permission to be remembered.
112 static void cancelPendingRequestsInOtherTabs(WebCore::String origin);
113 void cancelPendingRequests(WebCore::String origin);
115 static void maybeLoadPermanentPermissions();
116 static void maybeStorePermanentPermissions();
118 WebViewCore* m_webViewCore;
119 WebCore::Frame* m_mainFrame;
120 WebCore::String m_originInProgress;
121 typedef Vector<WebCore::String> OriginVector;
122 OriginVector m_queuedOrigins;
124 typedef WTF::HashMap<WebCore::String, bool> PermissionsMap;
125 PermissionsMap m_temporaryPermissions;
126 static PermissionsMap s_permanentPermissions;
128 typedef WTF::Vector<GeolocationPermissions*> GeolocationPermissionsVector;
129 static GeolocationPermissionsVector s_instances;
131 WebCore::Timer<GeolocationPermissions> m_timer;
133 struct CallbackData {
134 WebCore::String origin;
137 CallbackData m_callbackData;
139 static bool s_alwaysDeny;
141 static bool s_permanentPermissionsLoaded;
142 static WebCore::String s_databasePath;
145 } // namespace android