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