| 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 <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 // | 23 // |
| 24 // A PermissionBubbleManager is associated with a particular WebContents. | 24 // A PermissionBubbleManager is associated with a particular WebContents. |
| 25 // Requests attached to a particular WebContents' PBM must outlive it. | 25 // Requests attached to a particular WebContents' PBM must outlive it. |
| 26 // | 26 // |
| 27 // The PermissionBubbleManager should be addressed on the UI thread. | 27 // The PermissionBubbleManager should be addressed on the UI thread. |
| 28 class PermissionBubbleManager | 28 class PermissionBubbleManager |
| 29 : public content::WebContentsObserver, | 29 : public content::WebContentsObserver, |
| 30 public content::WebContentsUserData<PermissionBubbleManager>, | 30 public content::WebContentsUserData<PermissionBubbleManager>, |
| 31 public PermissionBubbleView::Delegate { | 31 public PermissionBubbleView::Delegate { |
| 32 public: | 32 public: |
| 33 enum AutoResponseType { |
| 34 NONE, |
| 35 ACCEPT_ALL, |
| 36 DENY_ALL, |
| 37 DISMISS |
| 38 }; |
| 39 |
| 33 // Return the enabled state of permissions bubbles. | 40 // Return the enabled state of permissions bubbles. |
| 34 // Controlled by a flag and FieldTrial. | 41 // Controlled by a flag and FieldTrial. |
| 35 static bool Enabled(); | 42 static bool Enabled(); |
| 36 | 43 |
| 37 ~PermissionBubbleManager() override; | 44 ~PermissionBubbleManager() override; |
| 38 | 45 |
| 39 // Adds a new request to the permission bubble. Ownership of the request | 46 // Adds a new request to the permission bubble. Ownership of the request |
| 40 // remains with the caller. The caller must arrange for the request to | 47 // remains with the caller. The caller must arrange for the request to |
| 41 // outlive the PermissionBubbleManager. If a bubble is visible when this | 48 // outlive the PermissionBubbleManager. If a bubble is visible when this |
| 42 // call is made, the request will be queued up and shown after the current | 49 // call is made, the request will be queued up and shown after the current |
| (...skipping 14 matching lines...) Expand all Loading... |
| 57 // means any existing permission bubble can no longer be shown. Does not | 64 // means any existing permission bubble can no longer be shown. Does not |
| 58 // take ownership of the view. | 65 // take ownership of the view. |
| 59 void SetView(PermissionBubbleView* view) override; | 66 void SetView(PermissionBubbleView* view) override; |
| 60 | 67 |
| 61 // Controls whether incoming permission requests require user gestures. | 68 // Controls whether incoming permission requests require user gestures. |
| 62 // If |required| is false, requests will be displayed as soon as they come in. | 69 // If |required| is false, requests will be displayed as soon as they come in. |
| 63 // If |required| is true, requests will be silently queued until a request | 70 // If |required| is true, requests will be silently queued until a request |
| 64 // comes in with a user gesture. | 71 // comes in with a user gesture. |
| 65 void RequireUserGesture(bool required); | 72 void RequireUserGesture(bool required); |
| 66 | 73 |
| 74 // Do NOT use this methods in production code. Use this methods in browser |
| 75 // tests that need to accept or deny permissions when requested in |
| 76 // JavaScript. Your test needs to set this appropriately, and then the bubble |
| 77 // will proceed as desired as soon as Show() is called. |
| 78 void set_auto_response_for_test(AutoResponseType response) { |
| 79 auto_response_for_test_ = response; |
| 80 } |
| 81 |
| 67 private: | 82 private: |
| 68 friend class DownloadRequestLimiterTest; | 83 friend class DownloadRequestLimiterTest; |
| 69 friend class GeolocationBrowserTest; | 84 friend class GeolocationBrowserTest; |
| 70 friend class GeolocationPermissionContextTests; | 85 friend class GeolocationPermissionContextTests; |
| 71 friend class GeolocationPermissionContextParamTests; | 86 friend class GeolocationPermissionContextParamTests; |
| 72 friend class PermissionBubbleManagerTest; | 87 friend class PermissionBubbleManagerTest; |
| 73 friend class PermissionContextBaseTests; | 88 friend class PermissionContextBaseTests; |
| 74 friend class content::WebContentsUserData<PermissionBubbleManager>; | 89 friend class content::WebContentsUserData<PermissionBubbleManager>; |
| 75 | 90 |
| 76 explicit PermissionBubbleManager(content::WebContents* web_contents); | 91 explicit PermissionBubbleManager(content::WebContents* web_contents); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 // is the same object as an existing request in |queue|, false otherwise. | 127 // is the same object as an existing request in |queue|, false otherwise. |
| 113 bool ExistingRequest(PermissionBubbleRequest* request, | 128 bool ExistingRequest(PermissionBubbleRequest* request, |
| 114 const std::vector<PermissionBubbleRequest*>& queue, | 129 const std::vector<PermissionBubbleRequest*>& queue, |
| 115 bool* same_object); | 130 bool* same_object); |
| 116 | 131 |
| 117 // Returns true if |queue| contains a request which was generated by a user | 132 // Returns true if |queue| contains a request which was generated by a user |
| 118 // gesture. Returns false otherwise. | 133 // gesture. Returns false otherwise. |
| 119 bool HasUserGestureRequest( | 134 bool HasUserGestureRequest( |
| 120 const std::vector<PermissionBubbleRequest*>& queue); | 135 const std::vector<PermissionBubbleRequest*>& queue); |
| 121 | 136 |
| 137 void DoAutoResponseForTesting(); |
| 138 |
| 122 // Whether to delay displaying the bubble until a request with a user gesture. | 139 // Whether to delay displaying the bubble until a request with a user gesture. |
| 123 // False by default, unless RequireUserGesture(bool) changes the value. | 140 // False by default, unless RequireUserGesture(bool) changes the value. |
| 124 bool require_user_gesture_; | 141 bool require_user_gesture_; |
| 125 | 142 |
| 126 // Whether or not we are showing the bubble in this tab. | 143 // Whether or not we are showing the bubble in this tab. |
| 127 bool bubble_showing_; | 144 bool bubble_showing_; |
| 128 | 145 |
| 129 // Set to the UI surface to be used to display the permissions requests. | 146 // Set to the UI surface to be used to display the permissions requests. |
| 130 PermissionBubbleView* view_; | 147 PermissionBubbleView* view_; |
| 131 | 148 |
| 132 std::vector<PermissionBubbleRequest*> requests_; | 149 std::vector<PermissionBubbleRequest*> requests_; |
| 133 std::vector<PermissionBubbleRequest*> queued_requests_; | 150 std::vector<PermissionBubbleRequest*> queued_requests_; |
| 134 std::vector<PermissionBubbleRequest*> queued_frame_requests_; | 151 std::vector<PermissionBubbleRequest*> queued_frame_requests_; |
| 135 | 152 |
| 136 // URL of the main frame in the WebContents to which this manager is attached. | 153 // URL of the main frame in the WebContents to which this manager is attached. |
| 137 // TODO(gbillock): if there are iframes in the page, we need to deal with it. | 154 // TODO(gbillock): if there are iframes in the page, we need to deal with it. |
| 138 GURL request_url_; | 155 GURL request_url_; |
| 139 bool request_url_has_loaded_; | 156 bool request_url_has_loaded_; |
| 140 | 157 |
| 141 std::vector<bool> accept_states_; | 158 std::vector<bool> accept_states_; |
| 142 | 159 |
| 160 AutoResponseType auto_response_for_test_; |
| 161 |
| 143 base::WeakPtrFactory<PermissionBubbleManager> weak_factory_; | 162 base::WeakPtrFactory<PermissionBubbleManager> weak_factory_; |
| 144 }; | 163 }; |
| 145 | 164 |
| 146 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_ | 165 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_ |
| OLD | NEW |