Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: chrome/browser/geolocation/geolocation_permission_context.h

Issue 330143002: Simplify geolocation permission request in the Content API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_GEOLOCATION_CHROME_GEOLOCATION_PERMISSION_CONTEXT_H_ 5 #ifndef CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_H_
6 #define CHROME_BROWSER_GEOLOCATION_CHROME_GEOLOCATION_PERMISSION_CONTEXT_H_ 6 #define CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/callback.h"
11 #include "base/containers/scoped_ptr_hash_map.h" 12 #include "base/containers/scoped_ptr_hash_map.h"
13 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
13 #include "chrome/browser/content_settings/permission_queue_controller.h" 15 #include "chrome/browser/content_settings/permission_queue_controller.h"
14 #include "chrome/browser/geolocation/chrome_geolocation_permission_context_exten sions.h" 16 #include "chrome/browser/geolocation/geolocation_permission_context_extensions.h "
15 #include "content/public/browser/geolocation_permission_context.h"
16 17
17 namespace content { 18 namespace content {
18 class WebContents; 19 class WebContents;
19 } 20 }
20 21
21 class GeolocationPermissionRequest; 22 class GeolocationPermissionRequest;
22 class PermissionRequestID; 23 class PermissionRequestID;
23 class Profile; 24 class Profile;
24 25
25 // Chrome specific implementation of GeolocationPermissionContext; manages 26 // This manages Geolocation permissions flow, and delegates UI handling via
26 // Geolocation permissions flow, and delegates UI handling via
27 // PermissionQueueController. 27 // PermissionQueueController.
28 class ChromeGeolocationPermissionContext 28 class GeolocationPermissionContext
29 : public content::GeolocationPermissionContext { 29 : public base::RefCountedThreadSafe<GeolocationPermissionContext> {
30 public: 30 public:
31 explicit ChromeGeolocationPermissionContext(Profile* profile); 31 explicit GeolocationPermissionContext(Profile* profile);
32 32
33 // GeolocationPermissionContext: 33 // See ContentBrowserClient method of the same name.
34 virtual void RequestGeolocationPermission( 34 void RequestGeolocationPermission(
35 content::WebContents* web_contents, 35 content::WebContents* web_contents,
36 int bridge_id, 36 int bridge_id,
37 const GURL& requesting_frame, 37 const GURL& requesting_frame,
38 bool user_gesture, 38 bool user_gesture,
39 base::Callback<void(bool)> callback) OVERRIDE; 39 base::Callback<void(bool)> result_callback,
40 virtual void CancelGeolocationPermissionRequest( 40 base::Closure* cancel_callback);
41 content::WebContents* web_contents,
42 int bridge_id,
43 const GURL& requesting_frame) OVERRIDE;
44 41
45 // Called on the UI thread when the profile is about to be destroyed. 42 // Called on the UI thread when the profile is about to be destroyed.
46 void ShutdownOnUIThread(); 43 void ShutdownOnUIThread();
47 44
48 // Notifies whether or not the corresponding bridge is allowed to use 45 // Notifies whether or not the corresponding bridge is allowed to use
49 // geolocation via 46 // geolocation via
50 // GeolocationPermissionContext::SetGeolocationPermissionResponse(). 47 // GeolocationPermissionContext::SetGeolocationPermissionResponse().
51 // Called on the UI thread. 48 // Called on the UI thread.
52 void NotifyPermissionSet(const PermissionRequestID& id, 49 void NotifyPermissionSet(const PermissionRequestID& id,
53 const GURL& requesting_frame, 50 const GURL& requesting_frame,
54 base::Callback<void(bool)> callback, 51 base::Callback<void(bool)> callback,
55 bool allowed); 52 bool allowed);
56 53
57 protected: 54 protected:
58 virtual ~ChromeGeolocationPermissionContext(); 55 virtual ~GeolocationPermissionContext();
59 56
60 Profile* profile() const { return profile_; } 57 Profile* profile() const { return profile_; }
61 58
62 // Return an instance of the infobar queue controller, creating it 59 // Return an instance of the infobar queue controller, creating it
63 // if necessary. 60 // if necessary.
64 PermissionQueueController* QueueController(); 61 PermissionQueueController* QueueController();
65 62
66 // ChromeGeolocationPermissionContext implementation: 63 void CancelGeolocationPermissionRequest(
64 int render_process_id,
65 int render_view_id,
66 int bridge_id);
67
68 // GeolocationPermissionContext implementation:
67 // Decide whether the geolocation permission should be granted. 69 // Decide whether the geolocation permission should be granted.
68 // Calls PermissionDecided if permission can be decided non-interactively, 70 // Calls PermissionDecided if permission can be decided non-interactively,
69 // or NotifyPermissionSet if permission decided by presenting an 71 // or NotifyPermissionSet if permission decided by presenting an
70 // infobar to the user. Called on the UI thread. 72 // infobar to the user. Called on the UI thread.
71 virtual void DecidePermission(content::WebContents* web_contents, 73 virtual void DecidePermission(content::WebContents* web_contents,
72 const PermissionRequestID& id, 74 const PermissionRequestID& id,
73 const GURL& requesting_frame, 75 const GURL& requesting_frame,
74 bool user_gesture, 76 bool user_gesture,
75 const GURL& embedder, 77 const GURL& embedder,
76 const std::string& accept_button_label, 78 const std::string& accept_button_label,
77 base::Callback<void(bool)> callback); 79 base::Callback<void(bool)> callback);
78 80
79 // Called when permission is granted without interactively asking 81 // Called when permission is granted without interactively asking
80 // the user. Can be overridden to introduce additional UI flow. 82 // the user. Can be overridden to introduce additional UI flow.
81 // Should ultimately ensure that NotifyPermissionSet is called. 83 // Should ultimately ensure that NotifyPermissionSet is called.
82 // Called on the UI thread. 84 // Called on the UI thread.
83 virtual void PermissionDecided(const PermissionRequestID& id, 85 virtual void PermissionDecided(const PermissionRequestID& id,
84 const GURL& requesting_frame, 86 const GURL& requesting_frame,
85 const GURL& embedder, 87 const GURL& embedder,
86 base::Callback<void(bool)> callback, 88 base::Callback<void(bool)> callback,
87 bool allowed); 89 bool allowed);
88 90
89 // Create an PermissionQueueController. overriden in derived classes to 91 // Create an PermissionQueueController. overriden in derived classes to
90 // provide additional UI flow. Called on the UI thread. 92 // provide additional UI flow. Called on the UI thread.
91 virtual PermissionQueueController* CreateQueueController(); 93 virtual PermissionQueueController* CreateQueueController();
92 94
93 private: 95 private:
96 friend class base::RefCountedThreadSafe<GeolocationPermissionContext>;
94 friend class GeolocationPermissionRequest; 97 friend class GeolocationPermissionRequest;
95 98
96 // Removes any pending InfoBar request. 99 // Removes any pending InfoBar request.
97 void CancelPendingInfobarRequest(const PermissionRequestID& id); 100 void CancelPendingInfobarRequest(const PermissionRequestID& id);
98 101
99 // Creates and show an info bar. 102 // Creates and show an info bar.
100 void CreateInfoBarRequest(const PermissionRequestID& id, 103 void CreateInfoBarRequest(const PermissionRequestID& id,
101 const GURL& requesting_frame, 104 const GURL& requesting_frame,
102 const GURL& embedder, 105 const GURL& embedder,
103 const std::string accept_button_label, 106 const std::string accept_button_label,
104 base::Callback<void(bool)> callback); 107 base::Callback<void(bool)> callback);
105 108
106 // Notify the context that a particular request object is no longer needed. 109 // Notify the context that a particular request object is no longer needed.
107 void RequestFinished(GeolocationPermissionRequest* request); 110 void RequestFinished(GeolocationPermissionRequest* request);
108 111
109 // These must only be accessed from the UI thread. 112 // These must only be accessed from the UI thread.
110 Profile* const profile_; 113 Profile* const profile_;
111 bool shutting_down_; 114 bool shutting_down_;
112 scoped_ptr<PermissionQueueController> permission_queue_controller_; 115 scoped_ptr<PermissionQueueController> permission_queue_controller_;
113 ChromeGeolocationPermissionContextExtensions extensions_context_; 116 GeolocationPermissionContextExtensions extensions_context_;
114 117
115 base::ScopedPtrHashMap<std::string, GeolocationPermissionRequest> 118 base::ScopedPtrHashMap<std::string, GeolocationPermissionRequest>
116 pending_requests_; 119 pending_requests_;
117 120
118 DISALLOW_COPY_AND_ASSIGN(ChromeGeolocationPermissionContext); 121 DISALLOW_COPY_AND_ASSIGN(GeolocationPermissionContext);
119 }; 122 };
120 123
121 #endif // CHROME_BROWSER_GEOLOCATION_CHROME_GEOLOCATION_PERMISSION_CONTEXT_H_ 124 #endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698