OLD | NEW |
---|---|
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_GEOLOCATION_INFOBAR_QUEUE_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_GEOLOCATION_GEOLOCATION_INFOBAR_QUEUE_CONTROLLER_H_ |
6 #define CHROME_BROWSER_GEOLOCATION_GEOLOCATION_INFOBAR_QUEUE_CONTROLLER_H_ | 6 #define CHROME_BROWSER_GEOLOCATION_GEOLOCATION_INFOBAR_QUEUE_CONTROLLER_H_ |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "content/public/browser/notification_observer.h" | 9 #include "content/public/browser/notification_observer.h" |
10 #include "content/public/browser/notification_registrar.h" | 10 #include "content/public/browser/notification_registrar.h" |
11 | 11 |
12 class GURL; | 12 class GURL; |
13 class GeolocationConfirmInfoBarDelegate; | 13 class GeolocationConfirmInfoBarDelegate; |
14 class InfoBarTabHelper; | 14 class InfoBarTabHelper; |
15 class Profile; | 15 class Profile; |
16 namespace content { | |
17 struct GeolocationPermissionRequestID; | |
18 } | |
16 | 19 |
17 // This class controls the geolocation infobar queue per profile, and it's | 20 // This class controls the geolocation infobar queue per profile, and it's |
18 // used by GeolocationPermissionContext. | 21 // used by GeolocationPermissionContext. |
19 // An alternate approach would be to have this queue per tab, and use | 22 // An alternate approach would be to have this queue per tab, and use |
20 // notifications to broadcast when permission is set / listen to notification to | 23 // notifications to broadcast when permission is set / listen to notification to |
21 // cancel pending requests. This may be specially useful if there are other | 24 // cancel pending requests. This may be specially useful if there are other |
22 // things listening for such notifications. | 25 // things listening for such notifications. |
23 // For the time being this class is self-contained and it doesn't seem pulling | 26 // For the time being this class is self-contained and it doesn't seem pulling |
24 // the notification infrastructure would simplify. | 27 // the notification infrastructure would simplify. |
25 class GeolocationInfoBarQueueController : content::NotificationObserver { | 28 class GeolocationInfoBarQueueController : content::NotificationObserver { |
26 public: | 29 public: |
27 typedef base::Callback<void(bool /* allowed */)> PermissionDecidedCallback; | 30 typedef base::Callback<void(bool /* allowed */)> PermissionDecidedCallback; |
28 | 31 |
29 explicit GeolocationInfoBarQueueController(Profile* profile); | 32 explicit GeolocationInfoBarQueueController(Profile* profile); |
30 virtual ~GeolocationInfoBarQueueController(); | 33 virtual ~GeolocationInfoBarQueueController(); |
31 | 34 |
32 // The InfoBar will be displayed immediately if the tab is not already | 35 // The InfoBar will be displayed immediately if the tab is not already |
33 // displaying one, otherwise it'll be queued. | 36 // displaying one, otherwise it'll be queued. |
34 void CreateInfoBarRequest(int render_process_id, | 37 void CreateInfoBarRequest(const content::GeolocationPermissionRequestID& id, |
35 int render_view_id, | |
36 int bridge_id, | |
37 const GURL& requesting_frame, | 38 const GURL& requesting_frame, |
38 const GURL& embedder, | 39 const GURL& embedder, |
39 PermissionDecidedCallback callback); | 40 PermissionDecidedCallback callback); |
40 | 41 |
41 // Cancels a specific infobar request. | 42 // Cancels a specific infobar request. |
42 void CancelInfoBarRequest(int render_process_id, | 43 void CancelInfoBarRequest(const content::GeolocationPermissionRequestID& id); |
43 int render_view_id, | |
44 int bridge_id); | |
45 | 44 |
46 // Called by the InfoBarDelegate to notify permission has been set. | 45 // Called by the InfoBarDelegate to notify permission has been set. |
47 // It'll notify and dismiss any other pending InfoBar request for the same | 46 // It'll notify and dismiss any other pending InfoBar request for the same |
48 // |requesting_frame| and embedder. | 47 // |requesting_frame| and embedder. |
49 void OnPermissionSet(int render_process_id, | 48 void OnPermissionSet(const content::GeolocationPermissionRequestID& id, |
50 int render_view_id, | |
51 int bridge_id, | |
52 const GURL& requesting_frame, | 49 const GURL& requesting_frame, |
53 const GURL& embedder, | 50 const GURL& embedder, |
54 bool update_content_setting, | 51 bool update_content_setting, |
55 bool allowed); | 52 bool allowed); |
56 | 53 |
57 // content::NotificationObserver | 54 // content::NotificationObserver |
58 virtual void Observe(int type, | 55 virtual void Observe(int type, |
59 const content::NotificationSource& source, | 56 const content::NotificationSource& source, |
60 const content::NotificationDetails& details) OVERRIDE; | 57 const content::NotificationDetails& details) OVERRIDE; |
61 | 58 |
62 protected: | 59 protected: |
63 // Create an Infobar delegate to ask the whether the requesting frame | 60 // Create an Infobar delegate to ask the whether the requesting frame |
64 // url should be granted geolocation permission. Overrided in | 61 // url should be granted geolocation permission. Overrided in |
65 // derived classes to implement alternative UI. | 62 // derived classes to implement alternative UI. |
66 virtual GeolocationConfirmInfoBarDelegate* CreateInfoBarDelegate( | 63 virtual GeolocationConfirmInfoBarDelegate* CreateInfoBarDelegate( |
67 InfoBarTabHelper* infobar_helper, | 64 InfoBarTabHelper* infobar_helper, |
68 GeolocationInfoBarQueueController* controller, | 65 GeolocationInfoBarQueueController* controller, |
69 int render_process_id, | 66 const content::GeolocationPermissionRequestID& id, |
70 int render_view_id, | |
71 int bridge_id, | |
72 const GURL& requesting_frame_url, | 67 const GURL& requesting_frame_url, |
73 const std::string& display_languages); | 68 const std::string& display_languages); |
74 | 69 |
75 private: | 70 private: |
76 struct PendingInfoBarRequest; | 71 struct PendingInfoBarRequest; |
77 class RequestEquals; | 72 class RequestEquals; |
78 | 73 |
79 typedef std::vector<PendingInfoBarRequest> PendingInfoBarRequests; | 74 typedef std::vector<PendingInfoBarRequest> PendingInfoBarRequests; |
80 | 75 |
81 // Shows the first pending infobar for this tab, if any. | 76 // Returns true if a geolocation infobar is already visible for the tab |
82 void ShowQueuedInfoBar(int render_process_id, int render_view_id, | 77 // corresponding to |id|. |
83 InfoBarTabHelper* helper); | 78 bool AlreadyShowingInfoBarForTab( |
John Knottenbelt
2012/10/24 10:59:10
Can you make this method const?
Peter Kasting
2012/10/24 19:50:48
Yes. Will fix.
| |
79 const content::GeolocationPermissionRequestID& id); | |
84 | 80 |
85 // Removes any pending requests for a given tab. | 81 // Shows the next pending infobar for the tab corresponding to |id|, if any. |
86 void ClearPendingInfoBarRequestsForTab(int render_process_id, | 82 // Note that this may not be the pending request whose ID is |id| if other |
87 int render_view_id); | 83 // requests are higher in the queue. Returns whether an infobar was shown. |
84 bool ShowQueuedInfoBarForTab( | |
85 const content::GeolocationPermissionRequestID& id); | |
88 | 86 |
89 InfoBarTabHelper* GetInfoBarHelper(int render_process_id, int render_view_id); | 87 void ClearPendingInfoBarRequestsForTab( |
90 bool AlreadyShowingInfoBar(int render_process_id, int render_view_id); | 88 const content::GeolocationPermissionRequestID& id); |
89 | |
90 InfoBarTabHelper* GetInfoBarHelper( | |
91 const content::GeolocationPermissionRequestID& id); | |
91 | 92 |
92 void RegisterForInfoBarNotifications(InfoBarTabHelper* helper); | 93 void RegisterForInfoBarNotifications(InfoBarTabHelper* helper); |
93 void UnregisterForInfoBarNotifications(InfoBarTabHelper* helper); | 94 void UnregisterForInfoBarNotifications(InfoBarTabHelper* helper); |
94 | 95 |
95 content::NotificationRegistrar registrar_; | 96 content::NotificationRegistrar registrar_; |
96 | 97 |
97 Profile* const profile_; | 98 Profile* const profile_; |
98 PendingInfoBarRequests pending_infobar_requests_; | 99 PendingInfoBarRequests pending_infobar_requests_; |
99 }; | 100 }; |
100 | 101 |
101 #endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_INFOBAR_QUEUE_CONTROLLER_H_ | 102 #endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_INFOBAR_QUEUE_CONTROLLER_H_ |
OLD | NEW |