| 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 |
| 145 // Posts a task which will allow the bubble to become visible if it is needed. | 150 // Posts a task which will allow the bubble to become visible if it is needed. |
| 146 void ScheduleShowBubble(); | 151 void ScheduleShowBubble(); |
| 147 | 152 |
| 148 // Shows the bubble if it is not already visible and there are pending | 153 // Shows the bubble if it is not already visible and there are pending |
| 149 // requests. | 154 // requests. |
| 150 void TriggerShowBubble(); | 155 void TriggerShowBubble(); |
| 151 | 156 |
| 152 // Finalize the pending permissions request. | 157 // Finalize the pending permissions request. |
| 153 void FinalizeBubble(); | 158 void FinalizeBubble(); |
| 154 | 159 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 // Whether each of the requests in |requests_| is accepted by the user. | 210 // Whether each of the requests in |requests_| is accepted by the user. |
| 206 std::vector<bool> accept_states_; | 211 std::vector<bool> accept_states_; |
| 207 | 212 |
| 208 base::ObserverList<Observer> observer_list_; | 213 base::ObserverList<Observer> observer_list_; |
| 209 AutoResponseType auto_response_for_test_; | 214 AutoResponseType auto_response_for_test_; |
| 210 | 215 |
| 211 base::WeakPtrFactory<PermissionRequestManager> weak_factory_; | 216 base::WeakPtrFactory<PermissionRequestManager> weak_factory_; |
| 212 }; | 217 }; |
| 213 | 218 |
| 214 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_REQUEST_MANAGER_H_ | 219 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_REQUEST_MANAGER_H_ |
| OLD | NEW |