blob: 4017210d402815d755a35e3383a687efc9eda780 [file] [log] [blame]
[email protected]c31d8042014-08-06 16:35:391// Copyright 2012 The Chromium Authors. All rights reserved.
[email protected]c476e632011-06-23 11:18:042// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]487974a2014-06-13 16:49:015#ifndef CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_H_
6#define CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_H_
[email protected]c476e632011-06-23 11:18:047
[email protected]1b6a1c22014-05-27 23:23:148#include <map>
[email protected]3ab14c62012-10-18 01:50:229#include <string>
10
[email protected]487974a2014-06-13 16:49:0111#include "base/callback.h"
[email protected]1b6a1c22014-05-27 23:23:1412#include "base/containers/scoped_ptr_hash_map.h"
[email protected]487974a2014-06-13 16:49:0113#include "base/memory/ref_counted.h"
[email protected]c476e632011-06-23 11:18:0414#include "base/memory/scoped_ptr.h"
[email protected]c0561cc82013-07-23 09:19:0415#include "chrome/browser/content_settings/permission_queue_controller.h"
[email protected]487974a2014-06-13 16:49:0116#include "chrome/browser/geolocation/geolocation_permission_context_extensions.h"
[email protected]c476e632011-06-23 11:18:0417
[email protected]f068ad0e2014-02-11 13:48:2318namespace content {
19class WebContents;
20}
21
[email protected]1b6a1c22014-05-27 23:23:1422class GeolocationPermissionRequest;
[email protected]c0561cc82013-07-23 09:19:0423class PermissionRequestID;
[email protected]c476e632011-06-23 11:18:0424class Profile;
25
[email protected]487974a2014-06-13 16:49:0126// This manages Geolocation permissions flow, and delegates UI handling via
[email protected]c0561cc82013-07-23 09:19:0427// PermissionQueueController.
[email protected]487974a2014-06-13 16:49:0128class GeolocationPermissionContext
29 : public base::RefCountedThreadSafe<GeolocationPermissionContext> {
[email protected]c476e632011-06-23 11:18:0430 public:
[email protected]487974a2014-06-13 16:49:0131 explicit GeolocationPermissionContext(Profile* profile);
[email protected]c715ce92012-06-18 08:26:3232
[email protected]487974a2014-06-13 16:49:0133 // See ContentBrowserClient method of the same name.
34 void RequestGeolocationPermission(
[email protected]f28ef9a32014-05-12 16:36:1035 content::WebContents* web_contents,
[email protected]0d5c08e2011-11-21 16:51:0636 int bridge_id,
[email protected]138d966c2011-11-30 00:49:2137 const GURL& requesting_frame,
[email protected]0e1886432014-04-10 13:26:2538 bool user_gesture,
[email protected]487974a2014-06-13 16:49:0139 base::Callback<void(bool)> result_callback,
40 base::Closure* cancel_callback);
[email protected]c476e632011-06-23 11:18:0441
[email protected]764ab69a2013-01-10 18:33:2142 // Called on the UI thread when the profile is about to be destroyed.
43 void ShutdownOnUIThread();
44
[email protected]0bcec202012-10-09 14:56:1945 // Notifies whether or not the corresponding bridge is allowed to use
46 // geolocation via
47 // GeolocationPermissionContext::SetGeolocationPermissionResponse().
[email protected]3ab14c62012-10-18 01:50:2248 // Called on the UI thread.
[email protected]c0561cc82013-07-23 09:19:0449 void NotifyPermissionSet(const PermissionRequestID& id,
[email protected]0bcec202012-10-09 14:56:1950 const GURL& requesting_frame,
51 base::Callback<void(bool)> callback,
52 bool allowed);
53
[email protected]f068ad0e2014-02-11 13:48:2354 protected:
[email protected]487974a2014-06-13 16:49:0155 virtual ~GeolocationPermissionContext();
[email protected]f068ad0e2014-02-11 13:48:2356
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
[email protected]487974a2014-06-13 16:49:0163 void CancelGeolocationPermissionRequest(
64 int render_process_id,
65 int render_view_id,
66 int bridge_id);
67
68 // GeolocationPermissionContext implementation:
[email protected]3ab14c62012-10-18 01:50:2269 // Decide whether the geolocation permission should be granted.
70 // Calls PermissionDecided if permission can be decided non-interactively,
71 // or NotifyPermissionSet if permission decided by presenting an
72 // infobar to the user. Called on the UI thread.
[email protected]f068ad0e2014-02-11 13:48:2373 virtual void DecidePermission(content::WebContents* web_contents,
74 const PermissionRequestID& id,
[email protected]3ab14c62012-10-18 01:50:2275 const GURL& requesting_frame,
[email protected]0e1886432014-04-10 13:26:2576 bool user_gesture,
[email protected]3ab14c62012-10-18 01:50:2277 const GURL& embedder,
78 base::Callback<void(bool)> callback);
79
80 // Called when permission is granted without interactively asking
81 // the user. Can be overridden to introduce additional UI flow.
82 // Should ultimately ensure that NotifyPermissionSet is called.
83 // Called on the UI thread.
[email protected]c0561cc82013-07-23 09:19:0484 virtual void PermissionDecided(const PermissionRequestID& id,
[email protected]3ab14c62012-10-18 01:50:2285 const GURL& requesting_frame,
86 const GURL& embedder,
87 base::Callback<void(bool)> callback,
88 bool allowed);
89
[email protected]c0561cc82013-07-23 09:19:0490 // Create an PermissionQueueController. overriden in derived classes to
91 // provide additional UI flow. Called on the UI thread.
92 virtual PermissionQueueController* CreateQueueController();
[email protected]3ab14c62012-10-18 01:50:2293
94 private:
[email protected]487974a2014-06-13 16:49:0195 friend class base::RefCountedThreadSafe<GeolocationPermissionContext>;
[email protected]1b6a1c22014-05-27 23:23:1496 friend class GeolocationPermissionRequest;
97
[email protected]3ab14c62012-10-18 01:50:2298 // Removes any pending InfoBar request.
[email protected]566755f82014-01-08 01:14:5799 void CancelPendingInfobarRequest(const PermissionRequestID& id);
[email protected]3ab14c62012-10-18 01:50:22100
[email protected]cc19a3262014-02-27 13:02:59101 // Creates and show an info bar.
102 void CreateInfoBarRequest(const PermissionRequestID& id,
103 const GURL& requesting_frame,
104 const GURL& embedder,
[email protected]cc19a3262014-02-27 13:02:59105 base::Callback<void(bool)> callback);
106
[email protected]1b6a1c22014-05-27 23:23:14107 // Notify the context that a particular request object is no longer needed.
108 void RequestFinished(GeolocationPermissionRequest* request);
109
[email protected]764ab69a2013-01-10 18:33:21110 // These must only be accessed from the UI thread.
[email protected]c476e632011-06-23 11:18:04111 Profile* const profile_;
[email protected]764ab69a2013-01-10 18:33:21112 bool shutting_down_;
[email protected]c0561cc82013-07-23 09:19:04113 scoped_ptr<PermissionQueueController> permission_queue_controller_;
[email protected]487974a2014-06-13 16:49:01114 GeolocationPermissionContextExtensions extensions_context_;
[email protected]c476e632011-06-23 11:18:04115
[email protected]1b6a1c22014-05-27 23:23:14116 base::ScopedPtrHashMap<std::string, GeolocationPermissionRequest>
117 pending_requests_;
118
[email protected]487974a2014-06-13 16:49:01119 DISALLOW_COPY_AND_ASSIGN(GeolocationPermissionContext);
[email protected]c476e632011-06-23 11:18:04120};
121
[email protected]487974a2014-06-13 16:49:01122#endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_H_