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