| 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_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_ |
| 6 #define CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_ | 6 #define CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_ |
| 7 | 7 |
| 8 #include <unordered_map> |
| 8 #include <vector> | 9 #include <vector> |
| 9 | 10 |
| 10 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 11 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 12 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
| 13 #include "chrome/browser/ui/website_settings/permission_bubble_view.h" | 14 #include "chrome/browser/ui/website_settings/permission_bubble_view.h" |
| 14 #include "content/public/browser/web_contents_observer.h" | 15 #include "content/public/browser/web_contents_observer.h" |
| 15 #include "content/public/browser/web_contents_user_data.h" | 16 #include "content/public/browser/web_contents_user_data.h" |
| 16 | 17 |
| 17 class PermissionBubbleRequest; | 18 class PermissionBubbleRequest; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 45 DISMISS | 46 DISMISS |
| 46 }; | 47 }; |
| 47 | 48 |
| 48 ~PermissionBubbleManager() override; | 49 ~PermissionBubbleManager() override; |
| 49 | 50 |
| 50 // Adds a new request to the permission bubble. Ownership of the request | 51 // Adds a new request to the permission bubble. Ownership of the request |
| 51 // remains with the caller. The caller must arrange for the request to | 52 // remains with the caller. The caller must arrange for the request to |
| 52 // outlive the PermissionBubbleManager. If a bubble is visible when this | 53 // outlive the PermissionBubbleManager. If a bubble is visible when this |
| 53 // call is made, the request will be queued up and shown after the current | 54 // call is made, the request will be queued up and shown after the current |
| 54 // bubble closes. A request with message text identical to an outstanding | 55 // bubble closes. A request with message text identical to an outstanding |
| 55 // request will receive a RequestFinished call immediately and not be added. | 56 // request will be merged with the outstanding request, and will have the same |
| 56 virtual void AddRequest(PermissionBubbleRequest* request); | 57 // callbacks called as the outstanding request. |
| 58 void AddRequest(PermissionBubbleRequest* request); |
| 57 | 59 |
| 58 // Cancels an outstanding request. This may have different effects depending | 60 // Cancels an outstanding request. This may have different effects depending |
| 59 // on what is going on with the bubble. If the request is pending, it will be | 61 // on what is going on with the bubble. If the request is pending, it will be |
| 60 // removed and never shown. If the request is showing, it will continue to be | 62 // removed and never shown. If the request is showing, it will continue to be |
| 61 // shown, but the user's action won't be reported back to the request object. | 63 // shown, but the user's action won't be reported back to the request object. |
| 62 // In some circumstances, we can remove the request from the bubble, and may | 64 // In some circumstances, we can remove the request from the bubble, and may |
| 63 // do so. The request will have RequestFinished executed on it if it is found, | 65 // do so. The request will have RequestFinished executed on it if it is found, |
| 64 // at which time the caller is free to delete the request. | 66 // at which time the caller is free to delete the request. |
| 65 virtual void CancelRequest(PermissionBubbleRequest* request); | 67 void CancelRequest(PermissionBubbleRequest* request); |
| 66 | 68 |
| 67 // Hides the bubble. | 69 // Hides the bubble. |
| 68 void HideBubble(); | 70 void HideBubble(); |
| 69 | 71 |
| 70 // Will show a permission bubble if there is a pending permission request on | 72 // Will show a permission bubble if there is a pending permission request on |
| 71 // the web contents that the PermissionBubbleManager belongs to. | 73 // the web contents that the PermissionBubbleManager belongs to. |
| 72 void DisplayPendingRequests(); | 74 void DisplayPendingRequests(); |
| 73 | 75 |
| 74 // Will reposition the bubble (may change parent if necessary). | 76 // Will reposition the bubble (may change parent if necessary). |
| 75 void UpdateAnchorPosition(); | 77 void UpdateAnchorPosition(); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 void TriggerShowBubble(); | 132 void TriggerShowBubble(); |
| 131 | 133 |
| 132 // Finalize the pending permissions request. | 134 // Finalize the pending permissions request. |
| 133 void FinalizeBubble(); | 135 void FinalizeBubble(); |
| 134 | 136 |
| 135 // Cancel any pending requests. This is called if the WebContents | 137 // Cancel any pending requests. This is called if the WebContents |
| 136 // on which permissions calls are pending is destroyed or navigated away | 138 // on which permissions calls are pending is destroyed or navigated away |
| 137 // from the requesting page. | 139 // from the requesting page. |
| 138 void CancelPendingQueues(); | 140 void CancelPendingQueues(); |
| 139 | 141 |
| 140 // Returns whether or not |request| has already been added to |queue|. | 142 // Searches |requests_|, |queued_requests_| and |queued_frame_requests_| - but |
| 141 // |same_object| must be non-null. It will be set to true if |request| | 143 // *not* |duplicate_requests_| - for a request matching |request|, and returns |
| 142 // is the same object as an existing request in |queue|, false otherwise. | 144 // the matching request, or |nullptr| if no match. Note that the matching |
| 143 bool ExistingRequest(PermissionBubbleRequest* request, | 145 // request may or may not be the same object as |request|. |
| 144 const std::vector<PermissionBubbleRequest*>& queue, | 146 PermissionBubbleRequest* GetExistingRequest(PermissionBubbleRequest* request); |
| 145 bool* same_object); | |
| 146 | 147 |
| 147 // Returns true if |queue| contains a request which was generated by a user | 148 // Returns true if |queue| contains a request which was generated by a user |
| 148 // gesture. Returns false otherwise. | 149 // gesture. Returns false otherwise. |
| 149 bool HasUserGestureRequest( | 150 bool HasUserGestureRequest( |
| 150 const std::vector<PermissionBubbleRequest*>& queue); | 151 const std::vector<PermissionBubbleRequest*>& queue); |
| 151 | 152 |
| 153 // Calls PermissionGranted on a request and all its duplicates. |
| 154 void PermissionGrantedIncludingDuplicates(PermissionBubbleRequest* request); |
| 155 // Calls PermissionDenied on a request and all its duplicates. |
| 156 void PermissionDeniedIncludingDuplicates(PermissionBubbleRequest* request); |
| 157 // Calls Cancelled on a request and all its duplicates. |
| 158 void CancelledIncludingDuplicates(PermissionBubbleRequest* request); |
| 159 // Calls RequestFinished on a request and all its duplicates. |
| 160 void RequestFinishedIncludingDuplicates(PermissionBubbleRequest* request); |
| 161 |
| 152 void NotifyBubbleAdded(); | 162 void NotifyBubbleAdded(); |
| 153 | 163 |
| 154 void DoAutoResponseForTesting(); | 164 void DoAutoResponseForTesting(); |
| 155 | 165 |
| 156 // Factory to be used to create views when needed. | 166 // Factory to be used to create views when needed. |
| 157 PermissionBubbleView::Factory view_factory_; | 167 PermissionBubbleView::Factory view_factory_; |
| 158 | 168 |
| 159 // The UI surface to be used to display the permissions requests. | 169 // The UI surface to be used to display the permissions requests. |
| 160 scoped_ptr<PermissionBubbleView> view_; | 170 scoped_ptr<PermissionBubbleView> view_; |
| 161 | 171 |
| 162 std::vector<PermissionBubbleRequest*> requests_; | 172 std::vector<PermissionBubbleRequest*> requests_; |
| 163 std::vector<PermissionBubbleRequest*> queued_requests_; | 173 std::vector<PermissionBubbleRequest*> queued_requests_; |
| 164 std::vector<PermissionBubbleRequest*> queued_frame_requests_; | 174 std::vector<PermissionBubbleRequest*> queued_frame_requests_; |
| 175 // Maps from the first request of a kind to subsequent requests that were |
| 176 // duped against it. |
| 177 std::unordered_multimap<PermissionBubbleRequest*, PermissionBubbleRequest*> |
| 178 duplicate_requests_; |
| 165 | 179 |
| 166 // URL of the main frame in the WebContents to which this manager is attached. | 180 // URL of the main frame in the WebContents to which this manager is attached. |
| 167 // TODO(gbillock): if there are iframes in the page, we need to deal with it. | 181 // TODO(gbillock): if there are iframes in the page, we need to deal with it. |
| 168 GURL request_url_; | 182 GURL request_url_; |
| 169 bool main_frame_has_fully_loaded_; | 183 bool main_frame_has_fully_loaded_; |
| 170 | 184 |
| 185 // Whether each of the requests in |requests_| is accepted by the user. |
| 171 std::vector<bool> accept_states_; | 186 std::vector<bool> accept_states_; |
| 172 | 187 |
| 173 base::ObserverList<Observer> observer_list_; | 188 base::ObserverList<Observer> observer_list_; |
| 174 AutoResponseType auto_response_for_test_; | 189 AutoResponseType auto_response_for_test_; |
| 175 | 190 |
| 176 base::WeakPtrFactory<PermissionBubbleManager> weak_factory_; | 191 base::WeakPtrFactory<PermissionBubbleManager> weak_factory_; |
| 177 }; | 192 }; |
| 178 | 193 |
| 179 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_ | 194 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_ |
| OLD | NEW |