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.
5 #ifndef CHROME_BROWSER_GEOLOCATION_CHROME_GEOLOCATION_PERMISSION_CONTEXT_H_
6 #define CHROME_BROWSER_GEOLOCATION_CHROME_GEOLOCATION_PERMISSION_CONTEXT_H_
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"
18 class PermissionRequestID
;
21 // Chrome specific implementation of GeolocationPermissionContext; manages
22 // Geolocation permissions flow, and delegates UI handling via
23 // PermissionQueueController.
24 class ChromeGeolocationPermissionContext
25 : public content::GeolocationPermissionContext
{
27 explicit ChromeGeolocationPermissionContext(Profile
* profile
);
29 // GeolocationPermissionContext:
30 virtual void RequestGeolocationPermission(
31 int render_process_id
,
34 const GURL
& requesting_frame
,
36 base::Callback
<void(bool)> callback
) OVERRIDE
;
37 virtual void CancelGeolocationPermissionRequest(
38 int render_process_id
,
41 const GURL
& requesting_frame
) OVERRIDE
;
43 // Called on the UI thread when the profile is about to be destroyed.
44 void ShutdownOnUIThread();
46 // Notifies whether or not the corresponding bridge is allowed to use
48 // GeolocationPermissionContext::SetGeolocationPermissionResponse().
49 // Called on the UI thread.
50 void NotifyPermissionSet(const PermissionRequestID
& id
,
51 const GURL
& requesting_frame
,
52 base::Callback
<void(bool)> callback
,
56 virtual ~ChromeGeolocationPermissionContext();
58 Profile
* profile() const { return profile_
; }
60 // Return an instance of the infobar queue controller, creating it
62 PermissionQueueController
* QueueController();
64 // ChromeGeolocationPermissionContext implementation:
65 // Decide whether the geolocation permission should be granted.
66 // Calls PermissionDecided if permission can be decided non-interactively,
67 // or NotifyPermissionSet if permission decided by presenting an
68 // infobar to the user. Called on the UI thread.
69 virtual void DecidePermission(content::WebContents
* web_contents
,
70 const PermissionRequestID
& id
,
71 const GURL
& requesting_frame
,
74 const std::string
& accept_button_label
,
75 base::Callback
<void(bool)> callback
);
77 // Called when permission is granted without interactively asking
78 // the user. Can be overridden to introduce additional UI flow.
79 // Should ultimately ensure that NotifyPermissionSet is called.
80 // Called on the UI thread.
81 virtual void PermissionDecided(const PermissionRequestID
& id
,
82 const GURL
& requesting_frame
,
84 base::Callback
<void(bool)> callback
,
87 // Create an PermissionQueueController. overriden in derived classes to
88 // provide additional UI flow. Called on the UI thread.
89 virtual PermissionQueueController
* CreateQueueController();
92 // Removes any pending InfoBar request.
93 void CancelPendingInfobarRequest(const PermissionRequestID
& id
);
95 // Creates and show an info bar.
96 void CreateInfoBarRequest(const PermissionRequestID
& id
,
97 const GURL
& requesting_frame
,
99 const std::string accept_button_label
,
100 base::Callback
<void(bool)> callback
);
102 // These must only be accessed from the UI thread.
103 Profile
* const profile_
;
105 scoped_ptr
<PermissionQueueController
> permission_queue_controller_
;
107 DISALLOW_COPY_AND_ASSIGN(ChromeGeolocationPermissionContext
);
110 #endif // CHROME_BROWSER_GEOLOCATION_CHROME_GEOLOCATION_PERMISSION_CONTEXT_H_