| 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/website_settings/permission_bubble_view.h" | 14 #include "chrome/browser/ui/website_settings/permission_prompt.h" |
| 15 #include "content/public/browser/web_contents_observer.h" | 15 #include "content/public/browser/web_contents_observer.h" |
| 16 #include "content/public/browser/web_contents_user_data.h" | 16 #include "content/public/browser/web_contents_user_data.h" |
| 17 | 17 |
| 18 class PermissionRequest; | 18 class PermissionRequest; |
| 19 | 19 |
| 20 namespace safe_browsing { | 20 namespace safe_browsing { |
| 21 class PermissionReporterBrowserTest; | 21 class PermissionReporterBrowserTest; |
| 22 } | 22 } |
| 23 | 23 |
| 24 // Provides access to permissions bubbles. Allows clients to add a request | 24 // Provides access to permissions bubbles. Allows clients to add a request |
| 25 // callback interface to the existing permission bubble configuration. | 25 // callback interface to the existing permission bubble configuration. |
| 26 // Depending on the situation and policy, that may add new UI to an existing | 26 // Depending on the situation and policy, that may add new UI to an existing |
| 27 // permission bubble, create and show a new permission bubble, or provide no | 27 // permission bubble, create and show a new permission bubble, or provide no |
| 28 // visible UI action at all. (In that case, the request will be immediately | 28 // visible UI action at all. (In that case, the request will be immediately |
| 29 // informed that the permission request failed.) | 29 // informed that the permission request failed.) |
| 30 // | 30 // |
| 31 // A PermissionRequestManager is associated with a particular WebContents. | 31 // A PermissionRequestManager is associated with a particular WebContents. |
| 32 // Requests attached to a particular WebContents' PBM must outlive it. | 32 // Requests attached to a particular WebContents' PBM must outlive it. |
| 33 // | 33 // |
| 34 // The PermissionRequestManager should be addressed on the UI thread. | 34 // The PermissionRequestManager should be addressed on the UI thread. |
| 35 class PermissionRequestManager | 35 class PermissionRequestManager |
| 36 : public content::WebContentsObserver, | 36 : public content::WebContentsObserver, |
| 37 public content::WebContentsUserData<PermissionRequestManager>, | 37 public content::WebContentsUserData<PermissionRequestManager>, |
| 38 public PermissionBubbleView::Delegate { | 38 public PermissionPrompt::Delegate { |
| 39 public: | 39 public: |
| 40 class Observer { | 40 class Observer { |
| 41 public: | 41 public: |
| 42 virtual ~Observer(); | 42 virtual ~Observer(); |
| 43 virtual void OnBubbleAdded(); | 43 virtual void OnBubbleAdded(); |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 enum AutoResponseType { | 46 enum AutoResponseType { |
| 47 NONE, | 47 NONE, |
| 48 ACCEPT_ALL, | 48 ACCEPT_ALL, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 // JavaScript. Your test needs to set this appropriately, and then the bubble | 97 // JavaScript. Your test needs to set this appropriately, and then the bubble |
| 98 // will proceed as desired as soon as Show() is called. | 98 // will proceed as desired as soon as Show() is called. |
| 99 void set_auto_response_for_test(AutoResponseType response) { | 99 void set_auto_response_for_test(AutoResponseType response) { |
| 100 auto_response_for_test_ = response; | 100 auto_response_for_test_ = response; |
| 101 } | 101 } |
| 102 | 102 |
| 103 private: | 103 private: |
| 104 // TODO(felt): Update testing so that it doesn't involve a lot of friends. | 104 // TODO(felt): Update testing so that it doesn't involve a lot of friends. |
| 105 friend class GeolocationBrowserTest; | 105 friend class GeolocationBrowserTest; |
| 106 friend class GeolocationPermissionContextTests; | 106 friend class GeolocationPermissionContextTests; |
| 107 friend class MockPermissionBubbleFactory; | 107 friend class MockPermissionPrompt; |
| 108 friend class MockPermissionBubbleView; | 108 friend class MockPermissionPromptFactory; |
| 109 friend class PermissionContextBaseTests; |
| 110 friend class PermissionRequestManagerTest; |
| 109 friend class safe_browsing::PermissionReporterBrowserTest; | 111 friend class safe_browsing::PermissionReporterBrowserTest; |
| 110 friend class PermissionRequestManagerTest; | |
| 111 friend class PermissionContextBaseTests; | |
| 112 friend class content::WebContentsUserData<PermissionRequestManager>; | 112 friend class content::WebContentsUserData<PermissionRequestManager>; |
| 113 FRIEND_TEST_ALL_PREFIXES(DownloadTest, TestMultipleDownloadsBubble); | 113 FRIEND_TEST_ALL_PREFIXES(DownloadTest, TestMultipleDownloadsBubble); |
| 114 | 114 |
| 115 explicit PermissionRequestManager(content::WebContents* web_contents); | 115 explicit PermissionRequestManager(content::WebContents* web_contents); |
| 116 | 116 |
| 117 // WebContentsObserver: | 117 // WebContentsObserver: |
| 118 void DidNavigateMainFrame( | 118 void DidNavigateMainFrame( |
| 119 const content::LoadCommittedDetails& details, | 119 const content::LoadCommittedDetails& details, |
| 120 const content::FrameNavigateParams& params) override; | 120 const content::FrameNavigateParams& params) override; |
| 121 void DocumentOnLoadCompletedInMainFrame() override; | 121 void DocumentOnLoadCompletedInMainFrame() override; |
| 122 void DocumentLoadedInFrame( | 122 void DocumentLoadedInFrame( |
| 123 content::RenderFrameHost* render_frame_host) override; | 123 content::RenderFrameHost* render_frame_host) override; |
| 124 void WebContentsDestroyed() override; | 124 void WebContentsDestroyed() override; |
| 125 | 125 |
| 126 // PermissionBubbleView::Delegate: | 126 // PermissionPrompt::Delegate: |
| 127 void ToggleAccept(int request_index, bool new_value) override; | 127 void ToggleAccept(int request_index, bool new_value) override; |
| 128 void Accept() override; | 128 void Accept() override; |
| 129 void Deny() override; | 129 void Deny() override; |
| 130 void Closing() override; | 130 void Closing() override; |
| 131 | 131 |
| 132 // Posts a task which will allow the bubble to become visible if it is needed. | 132 // Posts a task which will allow the bubble to become visible if it is needed. |
| 133 void ScheduleShowBubble(); | 133 void ScheduleShowBubble(); |
| 134 | 134 |
| 135 // Shows the bubble if it is not already visible and there are pending | 135 // Shows the bubble if it is not already visible and there are pending |
| 136 // requests. | 136 // requests. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 161 // Calls Cancelled on a request and all its duplicates. | 161 // Calls Cancelled on a request and all its duplicates. |
| 162 void CancelledIncludingDuplicates(PermissionRequest* request); | 162 void CancelledIncludingDuplicates(PermissionRequest* request); |
| 163 // Calls RequestFinished on a request and all its duplicates. | 163 // Calls RequestFinished on a request and all its duplicates. |
| 164 void RequestFinishedIncludingDuplicates(PermissionRequest* request); | 164 void RequestFinishedIncludingDuplicates(PermissionRequest* request); |
| 165 | 165 |
| 166 void NotifyBubbleAdded(); | 166 void NotifyBubbleAdded(); |
| 167 | 167 |
| 168 void DoAutoResponseForTesting(); | 168 void DoAutoResponseForTesting(); |
| 169 | 169 |
| 170 // Factory to be used to create views when needed. | 170 // Factory to be used to create views when needed. |
| 171 PermissionBubbleView::Factory view_factory_; | 171 PermissionPrompt::Factory view_factory_; |
| 172 | 172 |
| 173 // The UI surface to be used to display the permissions requests. | 173 // The UI surface to be used to display the permissions requests. |
| 174 std::unique_ptr<PermissionBubbleView> view_; | 174 std::unique_ptr<PermissionPrompt> view_; |
| 175 | 175 |
| 176 std::vector<PermissionRequest*> requests_; | 176 std::vector<PermissionRequest*> requests_; |
| 177 std::vector<PermissionRequest*> queued_requests_; | 177 std::vector<PermissionRequest*> queued_requests_; |
| 178 std::vector<PermissionRequest*> queued_frame_requests_; | 178 std::vector<PermissionRequest*> queued_frame_requests_; |
| 179 // Maps from the first request of a kind to subsequent requests that were | 179 // Maps from the first request of a kind to subsequent requests that were |
| 180 // duped against it. | 180 // duped against it. |
| 181 std::unordered_multimap<PermissionRequest*, PermissionRequest*> | 181 std::unordered_multimap<PermissionRequest*, PermissionRequest*> |
| 182 duplicate_requests_; | 182 duplicate_requests_; |
| 183 | 183 |
| 184 // URL of the main frame in the WebContents to which this manager is attached. | 184 // URL of the main frame in the WebContents to which this manager is attached. |
| 185 // TODO(gbillock): if there are iframes in the page, we need to deal with it. | 185 // TODO(gbillock): if there are iframes in the page, we need to deal with it. |
| 186 GURL request_url_; | 186 GURL request_url_; |
| 187 bool main_frame_has_fully_loaded_; | 187 bool main_frame_has_fully_loaded_; |
| 188 | 188 |
| 189 // Whether each of the requests in |requests_| is accepted by the user. | 189 // Whether each of the requests in |requests_| is accepted by the user. |
| 190 std::vector<bool> accept_states_; | 190 std::vector<bool> accept_states_; |
| 191 | 191 |
| 192 base::ObserverList<Observer> observer_list_; | 192 base::ObserverList<Observer> observer_list_; |
| 193 AutoResponseType auto_response_for_test_; | 193 AutoResponseType auto_response_for_test_; |
| 194 | 194 |
| 195 base::WeakPtrFactory<PermissionRequestManager> weak_factory_; | 195 base::WeakPtrFactory<PermissionRequestManager> weak_factory_; |
| 196 }; | 196 }; |
| 197 | 197 |
| 198 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_REQUEST_MANAGER_H_ | 198 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_REQUEST_MANAGER_H_ |
| OLD | NEW |