OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_H_ | 5 #ifndef CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_H_ |
6 #define CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_H_ | 6 #define CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_H_ |
7 | 7 |
8 #include <map> | |
9 #include <string> | |
10 | |
11 #include "base/callback.h" | 8 #include "base/callback.h" |
12 #include "base/containers/scoped_ptr_hash_map.h" | 9 #include "chrome/browser/content_settings/permission_context_base.h" |
13 #include "base/memory/ref_counted.h" | |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "chrome/browser/content_settings/permission_queue_controller.h" | |
16 #include "chrome/browser/geolocation/geolocation_permission_context_extensions.h
" | 10 #include "chrome/browser/geolocation/geolocation_permission_context_extensions.h
" |
17 | 11 |
18 namespace content { | 12 namespace content { |
19 class WebContents; | 13 class WebContents; |
20 } | 14 } |
21 | 15 |
22 class GeolocationPermissionRequest; | |
23 class PermissionRequestID; | 16 class PermissionRequestID; |
24 class Profile; | 17 class Profile; |
25 | 18 |
26 // This manages Geolocation permissions flow, and delegates UI handling via | 19 class GeolocationPermissionContext : public PermissionContextBase { |
27 // PermissionQueueController. | |
28 class GeolocationPermissionContext | |
29 : public base::RefCountedThreadSafe<GeolocationPermissionContext> { | |
30 public: | 20 public: |
31 explicit GeolocationPermissionContext(Profile* profile); | 21 explicit GeolocationPermissionContext(Profile* profile); |
32 | |
33 // See ContentBrowserClient method of the same name. | |
34 void RequestGeolocationPermission( | |
35 content::WebContents* web_contents, | |
36 int bridge_id, | |
37 const GURL& requesting_frame, | |
38 bool user_gesture, | |
39 base::Callback<void(bool)> result_callback, | |
40 base::Closure* cancel_callback); | |
41 | |
42 // Called on the UI thread when the profile is about to be destroyed. | |
43 void ShutdownOnUIThread(); | |
44 | |
45 // Notifies whether or not the corresponding bridge is allowed to use | |
46 // geolocation via | |
47 // GeolocationPermissionContext::SetGeolocationPermissionResponse(). | |
48 // Called on the UI thread. | |
49 void NotifyPermissionSet(const PermissionRequestID& id, | |
50 const GURL& requesting_frame, | |
51 base::Callback<void(bool)> callback, | |
52 bool allowed); | |
53 | |
54 protected: | |
55 virtual ~GeolocationPermissionContext(); | 22 virtual ~GeolocationPermissionContext(); |
56 | 23 |
57 Profile* profile() const { return profile_; } | |
58 | 24 |
59 // Return an instance of the infobar queue controller, creating it | 25 // In addition to the base class flow the geolocation permission request |
60 // if necessary. | 26 // checks that it is only code from valid iframes. |
61 PermissionQueueController* QueueController(); | 27 // It also adds special logic when called through an extension. |
| 28 virtual void RequestPermission(content::WebContents* web_contents, |
| 29 const PermissionRequestID& id, |
| 30 const GURL& requesting_frame_origin, |
| 31 bool user_gesture, |
| 32 const BrowserPermissionCallback& callback) OVERRIDE; |
62 | 33 |
63 void CancelGeolocationPermissionRequest( | 34 // Adds special logic when called through an extension. |
64 int render_process_id, | 35 virtual void CancelPermissionRequest(content::WebContents* web_contents, |
65 int render_view_id, | 36 const PermissionRequestID& id) OVERRIDE; |
66 int bridge_id); | |
67 | |
68 // GeolocationPermissionContext implementation: | |
69 // Decide whether the geolocation permission should be granted. | |
70 // Calls PermissionDecided if permission can be decided non-interactively, | |
71 // or NotifyPermissionSet if permission decided by presenting an | |
72 // infobar to the user. Called on the UI thread. | |
73 virtual void DecidePermission(content::WebContents* web_contents, | |
74 const PermissionRequestID& id, | |
75 const GURL& requesting_frame, | |
76 bool user_gesture, | |
77 const GURL& embedder, | |
78 base::Callback<void(bool)> callback); | |
79 | |
80 // Called when permission is granted without interactively asking | |
81 // the user. Can be overridden to introduce additional UI flow. | |
82 // Should ultimately ensure that NotifyPermissionSet is called. | |
83 // Called on the UI thread. | |
84 virtual void PermissionDecided(const PermissionRequestID& id, | |
85 const GURL& requesting_frame, | |
86 const GURL& embedder, | |
87 base::Callback<void(bool)> callback, | |
88 bool allowed); | |
89 | |
90 // Create an PermissionQueueController. overriden in derived classes to | |
91 // provide additional UI flow. Called on the UI thread. | |
92 virtual PermissionQueueController* CreateQueueController(); | |
93 | 37 |
94 private: | 38 private: |
95 friend class base::RefCountedThreadSafe<GeolocationPermissionContext>; | 39 virtual void UpdateTabContext(const PermissionRequestID& id, |
96 friend class GeolocationPermissionRequest; | 40 const GURL& requesting_frame, |
| 41 bool allowed) OVERRIDE; |
97 | 42 |
98 // Removes any pending InfoBar request. | 43 // This must only be accessed from the UI thread. |
99 void CancelPendingInfobarRequest(const PermissionRequestID& id); | |
100 | |
101 // Creates and show an info bar. | |
102 void CreateInfoBarRequest(const PermissionRequestID& id, | |
103 const GURL& requesting_frame, | |
104 const GURL& embedder, | |
105 base::Callback<void(bool)> callback); | |
106 | |
107 // Notify the context that a particular request object is no longer needed. | |
108 void RequestFinished(GeolocationPermissionRequest* request); | |
109 | |
110 // These must only be accessed from the UI thread. | |
111 Profile* const profile_; | |
112 bool shutting_down_; | |
113 scoped_ptr<PermissionQueueController> permission_queue_controller_; | |
114 GeolocationPermissionContextExtensions extensions_context_; | 44 GeolocationPermissionContextExtensions extensions_context_; |
115 | 45 |
116 base::ScopedPtrHashMap<std::string, GeolocationPermissionRequest> | |
117 pending_requests_; | |
118 | |
119 DISALLOW_COPY_AND_ASSIGN(GeolocationPermissionContext); | 46 DISALLOW_COPY_AND_ASSIGN(GeolocationPermissionContext); |
120 }; | 47 }; |
121 | 48 |
122 #endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_H_ | 49 #endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_H_ |
OLD | NEW |