OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_PERMISSIONS_PERMISSION_REQUEST_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_PERMISSIONS_PERMISSION_REQUEST_MANAGER_H_ |
6 #define CHROME_BROWSER_PERMISSIONS_PERMISSION_REQUEST_MANAGER_H_ | 6 #define CHROME_BROWSER_PERMISSIONS_PERMISSION_REQUEST_MANAGER_H_ |
7 | 7 |
8 #include <unordered_map> | 8 #include <unordered_map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
| 14 #include "chrome/browser/ui/browser_list_observer.h" |
14 #include "chrome/browser/ui/permission_bubble/permission_prompt.h" | 15 #include "chrome/browser/ui/permission_bubble/permission_prompt.h" |
15 #include "content/public/browser/web_contents_observer.h" | 16 #include "content/public/browser/web_contents_observer.h" |
16 #include "content/public/browser/web_contents_user_data.h" | 17 #include "content/public/browser/web_contents_user_data.h" |
17 | 18 |
18 class PermissionRequest; | 19 class PermissionRequest; |
19 | 20 |
20 namespace safe_browsing { | 21 namespace safe_browsing { |
21 class PermissionReporterBrowserTest; | 22 class PermissionReporterBrowserTest; |
22 } | 23 } |
23 | 24 |
24 namespace test { | 25 namespace test { |
25 class PermissionRequestManagerTestApi; | 26 class PermissionRequestManagerTestApi; |
26 } | 27 } |
27 | 28 |
28 // Provides access to permissions bubbles. Allows clients to add a request | 29 // Provides access to permissions bubbles. Allows clients to add a request |
29 // callback interface to the existing permission bubble configuration. | 30 // callback interface to the existing permission bubble configuration. |
30 // Depending on the situation and policy, that may add new UI to an existing | 31 // Depending on the situation and policy, that may add new UI to an existing |
31 // permission bubble, create and show a new permission bubble, or provide no | 32 // permission bubble, create and show a new permission bubble, or provide no |
32 // visible UI action at all. (In that case, the request will be immediately | 33 // visible UI action at all. (In that case, the request will be immediately |
33 // informed that the permission request failed.) | 34 // informed that the permission request failed.) |
34 // | 35 // |
35 // A PermissionRequestManager is associated with a particular WebContents. | 36 // A PermissionRequestManager is associated with a particular WebContents. |
36 // Requests attached to a particular WebContents' PBM must outlive it. | 37 // Requests attached to a particular WebContents' PBM must outlive it. |
37 // | 38 // |
38 // The PermissionRequestManager should be addressed on the UI thread. | 39 // The PermissionRequestManager should be addressed on the UI thread. |
39 class PermissionRequestManager | 40 class PermissionRequestManager |
40 : public content::WebContentsObserver, | 41 : public content::WebContentsObserver, |
41 public content::WebContentsUserData<PermissionRequestManager>, | 42 public content::WebContentsUserData<PermissionRequestManager>, |
42 public PermissionPrompt::Delegate { | 43 public PermissionPrompt::Delegate, |
| 44 public chrome::BrowserListObserver { |
43 public: | 45 public: |
44 class Observer { | 46 class Observer { |
45 public: | 47 public: |
46 virtual ~Observer(); | 48 virtual ~Observer(); |
47 virtual void OnBubbleAdded(); | 49 virtual void OnBubbleAdded(); |
48 }; | 50 }; |
49 | 51 |
50 enum AutoResponseType { | 52 enum AutoResponseType { |
51 NONE, | 53 NONE, |
52 ACCEPT_ALL, | 54 ACCEPT_ALL, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 content::RenderFrameHost* render_frame_host) override; | 137 content::RenderFrameHost* render_frame_host) override; |
136 void WebContentsDestroyed() override; | 138 void WebContentsDestroyed() override; |
137 | 139 |
138 // PermissionPrompt::Delegate: | 140 // PermissionPrompt::Delegate: |
139 void ToggleAccept(int request_index, bool new_value) override; | 141 void ToggleAccept(int request_index, bool new_value) override; |
140 void TogglePersist(bool new_value) override; | 142 void TogglePersist(bool new_value) override; |
141 void Accept() override; | 143 void Accept() override; |
142 void Deny() override; | 144 void Deny() override; |
143 void Closing() override; | 145 void Closing() override; |
144 | 146 |
| 147 // chrome::BrowserListObserver: |
| 148 void OnBrowserSetLastActive(Browser* browser) override; |
| 149 void OnBrowserNoLongerActive(Browser* browser) override; |
| 150 |
145 // Posts a task which will allow the bubble to become visible if it is needed. | 151 // Posts a task which will allow the bubble to become visible if it is needed. |
146 void ScheduleShowBubble(); | 152 void ScheduleShowBubble(); |
147 | 153 |
148 // Shows the bubble if it is not already visible and there are pending | 154 // Shows the bubble if it is not already visible and there are pending |
149 // requests. | 155 // requests. |
150 void TriggerShowBubble(); | 156 void TriggerShowBubble(); |
151 | 157 |
152 // Finalize the pending permissions request. | 158 // Finalize the pending permissions request. |
153 void FinalizeBubble(); | 159 void FinalizeBubble(); |
154 | 160 |
(...skipping 24 matching lines...) Expand all Loading... |
179 void NotifyBubbleAdded(); | 185 void NotifyBubbleAdded(); |
180 | 186 |
181 void DoAutoResponseForTesting(); | 187 void DoAutoResponseForTesting(); |
182 | 188 |
183 // Factory to be used to create views when needed. | 189 // Factory to be used to create views when needed. |
184 PermissionPrompt::Factory view_factory_; | 190 PermissionPrompt::Factory view_factory_; |
185 | 191 |
186 // The UI surface to be used to display the permissions requests. | 192 // The UI surface to be used to display the permissions requests. |
187 std::unique_ptr<PermissionPrompt> view_; | 193 std::unique_ptr<PermissionPrompt> view_; |
188 | 194 |
| 195 // Whether the browser that contains |web_contents()| is active. |
| 196 bool browser_active_; |
| 197 |
189 std::vector<PermissionRequest*> requests_; | 198 std::vector<PermissionRequest*> requests_; |
190 std::vector<PermissionRequest*> queued_requests_; | 199 std::vector<PermissionRequest*> queued_requests_; |
191 std::vector<PermissionRequest*> queued_frame_requests_; | 200 std::vector<PermissionRequest*> queued_frame_requests_; |
192 // Maps from the first request of a kind to subsequent requests that were | 201 // Maps from the first request of a kind to subsequent requests that were |
193 // duped against it. | 202 // duped against it. |
194 std::unordered_multimap<PermissionRequest*, PermissionRequest*> | 203 std::unordered_multimap<PermissionRequest*, PermissionRequest*> |
195 duplicate_requests_; | 204 duplicate_requests_; |
196 | 205 |
197 // URL of the main frame in the WebContents to which this manager is attached. | 206 // URL of the main frame in the WebContents to which this manager is attached. |
198 // TODO(gbillock): if there are iframes in the page, we need to deal with it. | 207 // TODO(gbillock): if there are iframes in the page, we need to deal with it. |
199 GURL request_url_; | 208 GURL request_url_; |
200 bool main_frame_has_fully_loaded_; | 209 bool main_frame_has_fully_loaded_; |
201 | 210 |
202 // Whether the response to each request should be persisted. | 211 // Whether the response to each request should be persisted. |
203 bool persist_; | 212 bool persist_; |
204 | 213 |
205 // Whether each of the requests in |requests_| is accepted by the user. | 214 // Whether each of the requests in |requests_| is accepted by the user. |
206 std::vector<bool> accept_states_; | 215 std::vector<bool> accept_states_; |
207 | 216 |
208 base::ObserverList<Observer> observer_list_; | 217 base::ObserverList<Observer> observer_list_; |
209 AutoResponseType auto_response_for_test_; | 218 AutoResponseType auto_response_for_test_; |
210 | 219 |
211 base::WeakPtrFactory<PermissionRequestManager> weak_factory_; | 220 base::WeakPtrFactory<PermissionRequestManager> weak_factory_; |
212 }; | 221 }; |
213 | 222 |
214 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_REQUEST_MANAGER_H_ | 223 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_REQUEST_MANAGER_H_ |
OLD | NEW |