Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / geolocation / chrome_geolocation_permission_context.h
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 namespace content {
15 class WebContents;
16 }
17
18 class PermissionRequestID;
19 class Profile;
20
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);
28
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       base::Callback<void(bool)> callback) OVERRIDE;
36   virtual void CancelGeolocationPermissionRequest(
37       int render_process_id,
38       int render_view_id,
39       int bridge_id,
40       const GURL& requesting_frame) OVERRIDE;
41
42   // Called on the UI thread when the profile is about to be destroyed.
43   void ShutdownOnUIThread();
44
45   // Notifies whether or not the corresponding bridge is allowed to use
46   // geolocation via
47   // GeolocationPermissionContext::SetGeolocationPermissionResponse().
48   // Called on the UI thread.
49   void NotifyPermissionSet(const PermissionRequestID& id,
50                            const GURL& requesting_frame,
51                            base::Callback<void(bool)> callback,
52                            bool allowed);
53
54  protected:
55   virtual ~ChromeGeolocationPermissionContext();
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
63   // ChromeGeolocationPermissionContext implementation:
64   // Decide whether the geolocation permission should be granted.
65   // Calls PermissionDecided if permission can be decided non-interactively,
66   // or NotifyPermissionSet if permission decided by presenting an
67   // infobar to the user. Called on the UI thread.
68   virtual void DecidePermission(content::WebContents* web_contents,
69                                 const PermissionRequestID& id,
70                                 const GURL& requesting_frame,
71                                 const GURL& embedder,
72                                 base::Callback<void(bool)> callback);
73
74   // Called when permission is granted without interactively asking
75   // the user. Can be overridden to introduce additional UI flow.
76   // Should ultimately ensure that NotifyPermissionSet is called.
77   // Called on the UI thread.
78   virtual void PermissionDecided(const PermissionRequestID& id,
79                                  const GURL& requesting_frame,
80                                  const GURL& embedder,
81                                  base::Callback<void(bool)> callback,
82                                  bool allowed);
83
84   // Create an PermissionQueueController. overriden in derived classes to
85   // provide additional UI flow.  Called on the UI thread.
86   virtual PermissionQueueController* CreateQueueController();
87
88  private:
89   // Removes any pending InfoBar request.
90   void CancelPendingInfobarRequest(const PermissionRequestID& id);
91
92   // These must only be accessed from the UI thread.
93   Profile* const profile_;
94   bool shutting_down_;
95   scoped_ptr<PermissionQueueController> permission_queue_controller_;
96
97   DISALLOW_COPY_AND_ASSIGN(ChromeGeolocationPermissionContext);
98 };
99
100 #endif  // CHROME_BROWSER_GEOLOCATION_CHROME_GEOLOCATION_PERMISSION_CONTEXT_H_