[safe-browsing] Database full hash matches like prefix match.
[chromium-blink-merge.git] / chrome / browser / geolocation / chrome_geolocation_permission_context.h
blobe590923a9c8e478113df9fa7e52c7cf71f2d800a
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_
8 #include <string>
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"
14 namespace content {
15 class WebContents;
18 class PermissionRequestID;
19 class Profile;
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 {
26 public:
27 explicit ChromeGeolocationPermissionContext(Profile* profile);
29 // GeolocationPermissionContext:
30 virtual void RequestGeolocationPermission(
31 int render_process_id,
32 int render_view_id,
33 int bridge_id,
34 const GURL& requesting_frame,
35 bool user_gesture,
36 base::Callback<void(bool)> callback) OVERRIDE;
37 virtual void CancelGeolocationPermissionRequest(
38 int render_process_id,
39 int render_view_id,
40 int bridge_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
47 // geolocation via
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,
53 bool allowed);
55 protected:
56 virtual ~ChromeGeolocationPermissionContext();
58 Profile* profile() const { return profile_; }
60 // Return an instance of the infobar queue controller, creating it
61 // if necessary.
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,
72 bool user_gesture,
73 const GURL& embedder,
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,
83 const GURL& embedder,
84 base::Callback<void(bool)> callback,
85 bool allowed);
87 // Create an PermissionQueueController. overriden in derived classes to
88 // provide additional UI flow. Called on the UI thread.
89 virtual PermissionQueueController* CreateQueueController();
91 private:
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,
98 const GURL& embedder,
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_;
104 bool shutting_down_;
105 scoped_ptr<PermissionQueueController> permission_queue_controller_;
107 DISALLOW_COPY_AND_ASSIGN(ChromeGeolocationPermissionContext);
110 #endif // CHROME_BROWSER_GEOLOCATION_CHROME_GEOLOCATION_PERMISSION_CONTEXT_H_