[email protected] | c31d804 | 2014-08-06 16:35:39 | [diff] [blame^] | 1 | // Copyright 2012 The Chromium Authors. All rights reserved. |
[email protected] | c476e63 | 2011-06-23 11:18:04 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 487974a | 2014-06-13 16:49:01 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_H_ |
| 6 | #define CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_H_ |
[email protected] | c476e63 | 2011-06-23 11:18:04 | [diff] [blame] | 7 | |
[email protected] | 1b6a1c2 | 2014-05-27 23:23:14 | [diff] [blame] | 8 | #include <map> |
[email protected] | 3ab14c6 | 2012-10-18 01:50:22 | [diff] [blame] | 9 | #include <string> |
| 10 | |
[email protected] | 487974a | 2014-06-13 16:49:01 | [diff] [blame] | 11 | #include "base/callback.h" |
[email protected] | 1b6a1c2 | 2014-05-27 23:23:14 | [diff] [blame] | 12 | #include "base/containers/scoped_ptr_hash_map.h" |
[email protected] | 487974a | 2014-06-13 16:49:01 | [diff] [blame] | 13 | #include "base/memory/ref_counted.h" |
[email protected] | c476e63 | 2011-06-23 11:18:04 | [diff] [blame] | 14 | #include "base/memory/scoped_ptr.h" |
[email protected] | c0561cc8 | 2013-07-23 09:19:04 | [diff] [blame] | 15 | #include "chrome/browser/content_settings/permission_queue_controller.h" |
[email protected] | 487974a | 2014-06-13 16:49:01 | [diff] [blame] | 16 | #include "chrome/browser/geolocation/geolocation_permission_context_extensions.h" |
[email protected] | c476e63 | 2011-06-23 11:18:04 | [diff] [blame] | 17 | |
[email protected] | f068ad0e | 2014-02-11 13:48:23 | [diff] [blame] | 18 | namespace content { |
| 19 | class WebContents; |
| 20 | } |
| 21 | |
[email protected] | 1b6a1c2 | 2014-05-27 23:23:14 | [diff] [blame] | 22 | class GeolocationPermissionRequest; |
[email protected] | c0561cc8 | 2013-07-23 09:19:04 | [diff] [blame] | 23 | class PermissionRequestID; |
[email protected] | c476e63 | 2011-06-23 11:18:04 | [diff] [blame] | 24 | class Profile; |
| 25 | |
[email protected] | 487974a | 2014-06-13 16:49:01 | [diff] [blame] | 26 | // This manages Geolocation permissions flow, and delegates UI handling via |
[email protected] | c0561cc8 | 2013-07-23 09:19:04 | [diff] [blame] | 27 | // PermissionQueueController. |
[email protected] | 487974a | 2014-06-13 16:49:01 | [diff] [blame] | 28 | class GeolocationPermissionContext |
| 29 | : public base::RefCountedThreadSafe<GeolocationPermissionContext> { |
[email protected] | c476e63 | 2011-06-23 11:18:04 | [diff] [blame] | 30 | public: |
[email protected] | 487974a | 2014-06-13 16:49:01 | [diff] [blame] | 31 | explicit GeolocationPermissionContext(Profile* profile); |
[email protected] | c715ce9 | 2012-06-18 08:26:32 | [diff] [blame] | 32 | |
[email protected] | 487974a | 2014-06-13 16:49:01 | [diff] [blame] | 33 | // See ContentBrowserClient method of the same name. |
| 34 | void RequestGeolocationPermission( |
[email protected] | f28ef9a3 | 2014-05-12 16:36:10 | [diff] [blame] | 35 | content::WebContents* web_contents, |
[email protected] | 0d5c08e | 2011-11-21 16:51:06 | [diff] [blame] | 36 | int bridge_id, |
[email protected] | 138d966c | 2011-11-30 00:49:21 | [diff] [blame] | 37 | const GURL& requesting_frame, |
[email protected] | 0e188643 | 2014-04-10 13:26:25 | [diff] [blame] | 38 | bool user_gesture, |
[email protected] | 487974a | 2014-06-13 16:49:01 | [diff] [blame] | 39 | base::Callback<void(bool)> result_callback, |
| 40 | base::Closure* cancel_callback); |
[email protected] | c476e63 | 2011-06-23 11:18:04 | [diff] [blame] | 41 | |
[email protected] | 764ab69a | 2013-01-10 18:33:21 | [diff] [blame] | 42 | // Called on the UI thread when the profile is about to be destroyed. |
| 43 | void ShutdownOnUIThread(); |
| 44 | |
[email protected] | 0bcec20 | 2012-10-09 14:56:19 | [diff] [blame] | 45 | // Notifies whether or not the corresponding bridge is allowed to use |
| 46 | // geolocation via |
| 47 | // GeolocationPermissionContext::SetGeolocationPermissionResponse(). |
[email protected] | 3ab14c6 | 2012-10-18 01:50:22 | [diff] [blame] | 48 | // Called on the UI thread. |
[email protected] | c0561cc8 | 2013-07-23 09:19:04 | [diff] [blame] | 49 | void NotifyPermissionSet(const PermissionRequestID& id, |
[email protected] | 0bcec20 | 2012-10-09 14:56:19 | [diff] [blame] | 50 | const GURL& requesting_frame, |
| 51 | base::Callback<void(bool)> callback, |
| 52 | bool allowed); |
| 53 | |
[email protected] | f068ad0e | 2014-02-11 13:48:23 | [diff] [blame] | 54 | protected: |
[email protected] | 487974a | 2014-06-13 16:49:01 | [diff] [blame] | 55 | virtual ~GeolocationPermissionContext(); |
[email protected] | f068ad0e | 2014-02-11 13:48:23 | [diff] [blame] | 56 | |
| 57 | Profile* profile() const { return profile_; } |
| 58 | |
| 59 | // Return an instance of the infobar queue controller, creating it |
| 60 | // if necessary. |
| 61 | PermissionQueueController* QueueController(); |
| 62 | |
[email protected] | 487974a | 2014-06-13 16:49:01 | [diff] [blame] | 63 | void CancelGeolocationPermissionRequest( |
| 64 | int render_process_id, |
| 65 | int render_view_id, |
| 66 | int bridge_id); |
| 67 | |
| 68 | // GeolocationPermissionContext implementation: |
[email protected] | 3ab14c6 | 2012-10-18 01:50:22 | [diff] [blame] | 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. |
[email protected] | f068ad0e | 2014-02-11 13:48:23 | [diff] [blame] | 73 | virtual void DecidePermission(content::WebContents* web_contents, |
| 74 | const PermissionRequestID& id, |
[email protected] | 3ab14c6 | 2012-10-18 01:50:22 | [diff] [blame] | 75 | const GURL& requesting_frame, |
[email protected] | 0e188643 | 2014-04-10 13:26:25 | [diff] [blame] | 76 | bool user_gesture, |
[email protected] | 3ab14c6 | 2012-10-18 01:50:22 | [diff] [blame] | 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. |
[email protected] | c0561cc8 | 2013-07-23 09:19:04 | [diff] [blame] | 84 | virtual void PermissionDecided(const PermissionRequestID& id, |
[email protected] | 3ab14c6 | 2012-10-18 01:50:22 | [diff] [blame] | 85 | const GURL& requesting_frame, |
| 86 | const GURL& embedder, |
| 87 | base::Callback<void(bool)> callback, |
| 88 | bool allowed); |
| 89 | |
[email protected] | c0561cc8 | 2013-07-23 09:19:04 | [diff] [blame] | 90 | // Create an PermissionQueueController. overriden in derived classes to |
| 91 | // provide additional UI flow. Called on the UI thread. |
| 92 | virtual PermissionQueueController* CreateQueueController(); |
[email protected] | 3ab14c6 | 2012-10-18 01:50:22 | [diff] [blame] | 93 | |
| 94 | private: |
[email protected] | 487974a | 2014-06-13 16:49:01 | [diff] [blame] | 95 | friend class base::RefCountedThreadSafe<GeolocationPermissionContext>; |
[email protected] | 1b6a1c2 | 2014-05-27 23:23:14 | [diff] [blame] | 96 | friend class GeolocationPermissionRequest; |
| 97 | |
[email protected] | 3ab14c6 | 2012-10-18 01:50:22 | [diff] [blame] | 98 | // Removes any pending InfoBar request. |
[email protected] | 566755f8 | 2014-01-08 01:14:57 | [diff] [blame] | 99 | void CancelPendingInfobarRequest(const PermissionRequestID& id); |
[email protected] | 3ab14c6 | 2012-10-18 01:50:22 | [diff] [blame] | 100 | |
[email protected] | cc19a326 | 2014-02-27 13:02:59 | [diff] [blame] | 101 | // Creates and show an info bar. |
| 102 | void CreateInfoBarRequest(const PermissionRequestID& id, |
| 103 | const GURL& requesting_frame, |
| 104 | const GURL& embedder, |
[email protected] | cc19a326 | 2014-02-27 13:02:59 | [diff] [blame] | 105 | base::Callback<void(bool)> callback); |
| 106 | |
[email protected] | 1b6a1c2 | 2014-05-27 23:23:14 | [diff] [blame] | 107 | // Notify the context that a particular request object is no longer needed. |
| 108 | void RequestFinished(GeolocationPermissionRequest* request); |
| 109 | |
[email protected] | 764ab69a | 2013-01-10 18:33:21 | [diff] [blame] | 110 | // These must only be accessed from the UI thread. |
[email protected] | c476e63 | 2011-06-23 11:18:04 | [diff] [blame] | 111 | Profile* const profile_; |
[email protected] | 764ab69a | 2013-01-10 18:33:21 | [diff] [blame] | 112 | bool shutting_down_; |
[email protected] | c0561cc8 | 2013-07-23 09:19:04 | [diff] [blame] | 113 | scoped_ptr<PermissionQueueController> permission_queue_controller_; |
[email protected] | 487974a | 2014-06-13 16:49:01 | [diff] [blame] | 114 | GeolocationPermissionContextExtensions extensions_context_; |
[email protected] | c476e63 | 2011-06-23 11:18:04 | [diff] [blame] | 115 | |
[email protected] | 1b6a1c2 | 2014-05-27 23:23:14 | [diff] [blame] | 116 | base::ScopedPtrHashMap<std::string, GeolocationPermissionRequest> |
| 117 | pending_requests_; |
| 118 | |
[email protected] | 487974a | 2014-06-13 16:49:01 | [diff] [blame] | 119 | DISALLOW_COPY_AND_ASSIGN(GeolocationPermissionContext); |
[email protected] | c476e63 | 2011-06-23 11:18:04 | [diff] [blame] | 120 | }; |
| 121 | |
[email protected] | 487974a | 2014-06-13 16:49:01 | [diff] [blame] | 122 | #endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_H_ |