| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_CHROME_GEOLOCATION_PERMISSION_CONTEXT_H_ | 5 #ifndef CHROME_BROWSER_GEOLOCATION_CHROME_GEOLOCATION_PERMISSION_CONTEXT_H_ |
| 6 #define CHROME_BROWSER_GEOLOCATION_CHROME_GEOLOCATION_PERMISSION_CONTEXT_H_ | 6 #define CHROME_BROWSER_GEOLOCATION_CHROME_GEOLOCATION_PERMISSION_CONTEXT_H_ |
| 7 | 7 |
| 8 #include <string> |
| 9 |
| 8 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 9 #include "content/public/browser/geolocation_permission_context.h" | 11 #include "content/public/browser/geolocation_permission_context.h" |
| 10 | 12 |
| 11 class GeolocationInfoBarQueueController; | 13 class GeolocationInfoBarQueueController; |
| 12 class PrefService; | 14 class PrefService; |
| 13 class Profile; | 15 class Profile; |
| 14 | 16 |
| 15 // Chrome specific implementation of GeolocationPermissionContext; manages | 17 // Chrome specific implementation of GeolocationPermissionContext; manages |
| 16 // Geolocation permissions flow, and delegates UI handling via | 18 // Geolocation permissions flow, and delegates UI handling via |
| 17 // GeolocationInfoBarQueueController. | 19 // GeolocationInfoBarQueueController. |
| 18 class ChromeGeolocationPermissionContext | 20 class ChromeGeolocationPermissionContext |
| 19 : public content::GeolocationPermissionContext { | 21 : public content::GeolocationPermissionContext { |
| 20 public: | 22 public: |
| 21 explicit ChromeGeolocationPermissionContext(Profile* profile); | 23 static ChromeGeolocationPermissionContext* Create(Profile* profile); |
| 22 | 24 |
| 23 static void RegisterUserPrefs(PrefService *user_prefs); | 25 static void RegisterUserPrefs(PrefService *user_prefs); |
| 24 | 26 |
| 25 // GeolocationPermissionContext implementation: | 27 // GeolocationPermissionContext implementation: |
| 26 virtual void RequestGeolocationPermission( | 28 virtual void RequestGeolocationPermission( |
| 27 int render_process_id, | 29 int render_process_id, |
| 28 int render_view_id, | 30 int render_view_id, |
| 29 int bridge_id, | 31 int bridge_id, |
| 30 const GURL& requesting_frame, | 32 const GURL& requesting_frame, |
| 31 base::Callback<void(bool)> callback) OVERRIDE; | 33 base::Callback<void(bool)> callback) OVERRIDE; |
| 32 virtual void CancelGeolocationPermissionRequest( | 34 virtual void CancelGeolocationPermissionRequest( |
| 33 int render_process_id, | 35 int render_process_id, |
| 34 int render_view_id, | 36 int render_view_id, |
| 35 int bridge_id, | 37 int bridge_id, |
| 36 const GURL& requesting_frame) OVERRIDE; | 38 const GURL& requesting_frame) OVERRIDE; |
| 37 | 39 |
| 38 private: | 40 protected: |
| 41 explicit ChromeGeolocationPermissionContext(Profile* profile); |
| 39 virtual ~ChromeGeolocationPermissionContext(); | 42 virtual ~ChromeGeolocationPermissionContext(); |
| 40 | 43 |
| 41 // Removes any pending InfoBar request. | 44 Profile* profile() const { return profile_; } |
| 42 void CancelPendingInfoBarRequest(int render_process_id, | 45 |
| 43 int render_view_id, | 46 // Return an instance of the infobar queue controller, creating it |
| 44 int bridge_id); | 47 // if necessary. |
| 48 GeolocationInfoBarQueueController* QueueController(); |
| 45 | 49 |
| 46 // Notifies whether or not the corresponding bridge is allowed to use | 50 // Notifies whether or not the corresponding bridge is allowed to use |
| 47 // geolocation via | 51 // geolocation via |
| 48 // GeolocationPermissionContext::SetGeolocationPermissionResponse(). | 52 // GeolocationPermissionContext::SetGeolocationPermissionResponse(). |
| 53 // Called on the UI thread. |
| 49 void NotifyPermissionSet(int render_process_id, | 54 void NotifyPermissionSet(int render_process_id, |
| 50 int render_view_id, | 55 int render_view_id, |
| 51 int bridge_id, | 56 int bridge_id, |
| 52 const GURL& requesting_frame, | 57 const GURL& requesting_frame, |
| 53 base::Callback<void(bool)> callback, | 58 base::Callback<void(bool)> callback, |
| 54 bool allowed); | 59 bool allowed); |
| 55 | 60 |
| 61 // ChromeGeolocationPermissionContext implementation: |
| 62 // Decide whether the geolocation permission should be granted. |
| 63 // Calls PermissionDecided if permission can be decided non-interactively, |
| 64 // or NotifyPermissionSet if permission decided by presenting an |
| 65 // infobar to the user. Called on the UI thread. |
| 66 virtual void DecidePermission(int render_process_id, |
| 67 int render_view_id, |
| 68 int bridge_id, |
| 69 const GURL& requesting_frame, |
| 70 const GURL& embedder, |
| 71 base::Callback<void(bool)> callback); |
| 72 |
| 73 // Called when permission is granted without interactively asking |
| 74 // the user. Can be overridden to introduce additional UI flow. |
| 75 // Should ultimately ensure that NotifyPermissionSet is called. |
| 76 // Called on the UI thread. |
| 77 virtual void PermissionDecided(int render_process_id, |
| 78 int render_view_id, |
| 79 int bridge_id, |
| 80 const GURL& requesting_frame, |
| 81 const GURL& embedder, |
| 82 base::Callback<void(bool)> callback, |
| 83 bool allowed); |
| 84 |
| 85 // Create an InfoBarQueueController. overriden in derived classes to provide |
| 86 // additional UI flow. Called on the UI thread. |
| 87 virtual GeolocationInfoBarQueueController* CreateQueueController(); |
| 88 |
| 89 private: |
| 90 // Removes any pending InfoBar request. |
| 91 void CancelPendingInfoBarRequest(int render_process_id, |
| 92 int render_view_id, |
| 93 int bridge_id); |
| 94 |
| 56 // This must only be accessed from the UI thread. | 95 // This must only be accessed from the UI thread. |
| 57 Profile* const profile_; | 96 Profile* const profile_; |
| 58 | 97 |
| 59 scoped_ptr<GeolocationInfoBarQueueController> | 98 scoped_ptr<GeolocationInfoBarQueueController> |
| 60 geolocation_infobar_queue_controller_; | 99 geolocation_infobar_queue_controller_; |
| 61 | 100 |
| 62 DISALLOW_COPY_AND_ASSIGN(ChromeGeolocationPermissionContext); | 101 DISALLOW_COPY_AND_ASSIGN(ChromeGeolocationPermissionContext); |
| 63 }; | 102 }; |
| 64 | 103 |
| 65 #endif // CHROME_BROWSER_GEOLOCATION_CHROME_GEOLOCATION_PERMISSION_CONTEXT_H_ | 104 #endif // CHROME_BROWSER_GEOLOCATION_CHROME_GEOLOCATION_PERMISSION_CONTEXT_H_ |
| OLD | NEW |