Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Side by Side Diff: chrome/browser/ui/website_settings/permission_bubble_manager.h

Issue 1251633002: Add BubbleManager to manage bubbles and ChromeBubbleManager for events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Apply Feedback Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/gtest_prod_util.h" 10 #include "base/gtest_prod_util.h"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/observer_list.h" 12 #include "base/observer_list.h"
13 #include "chrome/browser/ui/website_settings/permission_bubble_view.h" 13 #include "components/bubble/bubble_manager.h"
14 #include "content/public/browser/web_contents_observer.h" 14 #include "content/public/browser/web_contents_observer.h"
15 #include "content/public/browser/web_contents_user_data.h" 15 #include "content/public/browser/web_contents_user_data.h"
16 16
17 class BubbleManager;
17 class PermissionBubbleRequest; 18 class PermissionBubbleRequest;
18 19
20 // TODO(hcarmona): Rename to PermissionRequestQueue or PermissionRequestManager.
21
19 // Provides access to permissions bubbles. Allows clients to add a request 22 // Provides access to permissions bubbles. Allows clients to add a request
20 // callback interface to the existing permission bubble configuration. 23 // callback interface to the existing permission bubble configuration.
21 // Depending on the situation and policy, that may add new UI to an existing 24 // Depending on the situation and policy, that may add new UI to an existing
22 // permission bubble, create and show a new permission bubble, or provide no 25 // permission bubble, create and show a new permission bubble, or provide no
23 // visible UI action at all. (In that case, the request will be immediately 26 // visible UI action at all. (In that case, the request will be immediately
24 // informed that the permission request failed.) 27 // informed that the permission request failed.)
25 // 28 //
26 // A PermissionBubbleManager is associated with a particular WebContents. 29 // A PermissionBubbleManager is associated with a particular WebContents.
27 // Requests attached to a particular WebContents' PBM must outlive it. 30 // Requests attached to a particular WebContents' PBM must outlive it.
28 // 31 //
29 // The PermissionBubbleManager should be addressed on the UI thread. 32 // The PermissionBubbleManager should be addressed on the UI thread.
30 class PermissionBubbleManager 33 class PermissionBubbleManager
31 : public content::WebContentsObserver, 34 : public content::WebContentsObserver,
32 public content::WebContentsUserData<PermissionBubbleManager>, 35 public content::WebContentsUserData<PermissionBubbleManager> {
33 public PermissionBubbleView::Delegate {
34 public: 36 public:
35 class Observer { 37 class Observer {
36 public: 38 public:
37 virtual ~Observer(); 39 virtual ~Observer();
38 virtual void OnBubbleAdded(); 40 virtual void OnBubbleAdded();
39 }; 41 };
40 42
41 enum AutoResponseType { 43 enum AutoResponseType {
42 NONE, 44 NONE,
43 ACCEPT_ALL, 45 ACCEPT_ALL,
(...skipping 17 matching lines...) Expand all
61 63
62 // Cancels an outstanding request. This may have different effects depending 64 // Cancels an outstanding request. This may have different effects depending
63 // on what is going on with the bubble. If the request is pending, it will be 65 // on what is going on with the bubble. If the request is pending, it will be
64 // removed and never shown. If the request is showing, it will continue to be 66 // removed and never shown. If the request is showing, it will continue to be
65 // shown, but the user's action won't be reported back to the request object. 67 // shown, but the user's action won't be reported back to the request object.
66 // In some circumstances, we can remove the request from the bubble, and may 68 // In some circumstances, we can remove the request from the bubble, and may
67 // do so. The request will have RequestFinished executed on it if it is found, 69 // do so. The request will have RequestFinished executed on it if it is found,
68 // at which time the caller is free to delete the request. 70 // at which time the caller is free to delete the request.
69 virtual void CancelRequest(PermissionBubbleRequest* request); 71 virtual void CancelRequest(PermissionBubbleRequest* request);
70 72
71 // Hides the bubble.
72 void HideBubble();
73
74 // Will show a permission bubble if there is a pending permission request on
75 // the web contents that the PermissionBubbleManager belongs to.
76 void DisplayPendingRequests(Browser* browser);
77
78 // Will reposition the bubble (may change parent if necessary).
79 void UpdateAnchorPosition();
80
81 // True if a permission bubble is currently visible.
82 // TODO(hcarmona): Remove this as part of the bubble API work.
83 bool IsBubbleVisible();
84
85 // Get the native window of the bubble.
86 // TODO(hcarmona): Remove this as part of the bubble API work.
87 gfx::NativeWindow GetBubbleWindow();
88
89 // Controls whether incoming permission requests require user gestures. 73 // Controls whether incoming permission requests require user gestures.
90 // If |required| is false, requests will be displayed as soon as they come in. 74 // If |required| is false, requests will be displayed as soon as they come in.
91 // If |required| is true, requests will be silently queued until a request 75 // If |required| is true, requests will be silently queued until a request
92 // comes in with a user gesture. 76 // comes in with a user gesture.
93 void RequireUserGesture(bool required); 77 void RequireUserGesture(bool required);
94 78
95 // For observing the status of the permission bubble manager. 79 // For observing the status of the permission bubble manager.
96 void AddObserver(Observer* observer); 80 void AddObserver(Observer* observer);
97 void RemoveObserver(Observer* observer); 81 void RemoveObserver(Observer* observer);
98 82
99 // Do NOT use this methods in production code. Use this methods in browser 83 // Do NOT use this methods in production code. Use this methods in browser
100 // tests that need to accept or deny permissions when requested in 84 // tests that need to accept or deny permissions when requested in
101 // JavaScript. Your test needs to set this appropriately, and then the bubble 85 // JavaScript. Your test needs to set this appropriately, and then the bubble
102 // will proceed as desired as soon as Show() is called. 86 // will proceed as desired as soon as Show() is called.
103 void set_auto_response_for_test(AutoResponseType response) { 87 void set_auto_response_for_test(AutoResponseType response) {
104 auto_response_for_test_ = response; 88 auto_response_for_test_ = response;
105 } 89 }
106 90
91 const std::vector<PermissionBubbleRequest*>& requests() const {
92 return requests_;
93 }
94
95 const std::vector<bool>& accept_states() const { return accept_states_; }
96
97 void ToggleAccept(int request_index, bool new_value);
98 void Accept();
99 void Deny();
100 void Closing();
101
102 // Finalize the pending permissions. Called after the bubble is closed.
103 void DidClose();
104
107 private: 105 private:
108 // TODO(felt): Update testing so that it doesn't involve a lot of friends. 106 // TODO(felt): Update testing so that it doesn't involve a lot of friends.
109 friend class DownloadRequestLimiterTest; 107 friend class DownloadRequestLimiterTest;
110 friend class GeolocationBrowserTest; 108 friend class GeolocationBrowserTest;
111 friend class GeolocationPermissionContextTests; 109 friend class GeolocationPermissionContextTests;
112 friend class MockPermissionBubbleView; 110 friend class MockPermissionBubbleView;
113 friend class PermissionBubbleManagerTest; 111 friend class PermissionBubbleManagerTest;
114 friend class PermissionContextBaseTests; 112 friend class PermissionContextBaseTests;
115 friend class content::WebContentsUserData<PermissionBubbleManager>; 113 friend class content::WebContentsUserData<PermissionBubbleManager>;
116 FRIEND_TEST_ALL_PREFIXES(DownloadTest, TestMultipleDownloadsBubble); 114 FRIEND_TEST_ALL_PREFIXES(DownloadTest, TestMultipleDownloadsBubble);
117 115
118 explicit PermissionBubbleManager(content::WebContents* web_contents); 116 explicit PermissionBubbleManager(content::WebContents* web_contents);
119 117
120 // WebContentsObserver: 118 // WebContentsObserver:
121 void DidNavigateMainFrame( 119 void DidNavigateMainFrame(
122 const content::LoadCommittedDetails& details, 120 const content::LoadCommittedDetails& details,
123 const content::FrameNavigateParams& params) override; 121 const content::FrameNavigateParams& params) override;
124 void DocumentOnLoadCompletedInMainFrame() override; 122 void DocumentOnLoadCompletedInMainFrame() override;
125 void DocumentLoadedInFrame( 123 void DocumentLoadedInFrame(
126 content::RenderFrameHost* render_frame_host) override; 124 content::RenderFrameHost* render_frame_host) override;
127 125
128 // If a page on which permissions requests are pending is navigated, 126 // If a page on which permissions requests are pending is navigated,
129 // they will be finalized as if canceled by the user. 127 // they will be finalized as if canceled by the user.
msw 2015/08/13 03:37:21 Is simulating cancellation by the user really nece
130 void NavigationEntryCommitted(
131 const content::LoadCommittedDetails& details) override;
132 void WebContentsDestroyed() override; 128 void WebContentsDestroyed() override;
133 129
134 // PermissionBubbleView::Delegate:
135 void ToggleAccept(int request_index, bool new_value) override;
136 void Accept() override;
137 void Deny() override;
138 void Closing() override;
139
140 // Posts a task which will allow the bubble to become visible if it is needed.
141 void ScheduleShowBubble(); 130 void ScheduleShowBubble();
142 131
143 // Shows the bubble if it is not already visible and there are pending 132 // Shows the bubble if it is not already visible and there are pending
144 // requests. 133 // requests.
145 void TriggerShowBubble(); 134 void TriggerShowBubble();
146 135
147 // Finalize the pending permissions request. 136 // Closes the bubble.
msw 2015/08/13 03:37:21 comment not necessary.
148 void FinalizeBubble(); 137 void CloseBubble();
149 138
150 // Cancel any pending requests. This is called if the WebContents 139 // Cancel any pending requests. This is called if the WebContents
151 // on which permissions calls are pending is destroyed or navigated away 140 // on which permissions calls are pending is destroyed or navigated away
152 // from the requesting page. 141 // from the requesting page.
153 void CancelPendingQueues(); 142 void CancelPendingQueues();
154 143
155 // Returns whether or not |request| has already been added to |queue|. 144 // Returns whether or not |request| has already been added to |queue|.
156 // |same_object| must be non-null. It will be set to true if |request| 145 // |same_object| must be non-null. It will be set to true if |request|
157 // is the same object as an existing request in |queue|, false otherwise. 146 // is the same object as an existing request in |queue|, false otherwise.
158 bool ExistingRequest(PermissionBubbleRequest* request, 147 bool ExistingRequest(PermissionBubbleRequest* request,
159 const std::vector<PermissionBubbleRequest*>& queue, 148 const std::vector<PermissionBubbleRequest*>& queue,
160 bool* same_object); 149 bool* same_object);
161 150
162 // Returns true if |queue| contains a request which was generated by a user 151 // Returns true if |queue| contains a request which was generated by a user
163 // gesture. Returns false otherwise. 152 // gesture. Returns false otherwise.
164 bool HasUserGestureRequest( 153 bool HasUserGestureRequest(
165 const std::vector<PermissionBubbleRequest*>& queue); 154 const std::vector<PermissionBubbleRequest*>& queue);
166 155
156 BubbleManager* GetBubbleManager();
157
167 void NotifyBubbleAdded(); 158 void NotifyBubbleAdded();
168 159
169 void DoAutoResponseForTesting(); 160 void DoAutoResponseForTesting();
170 161
162 // True if a permission bubble is currently visible.
163 bool IsBubbleVisible();
164
171 // Whether to delay displaying the bubble until a request with a user gesture. 165 // Whether to delay displaying the bubble until a request with a user gesture.
172 // False by default, unless RequireUserGesture(bool) changes the value. 166 // False by default, unless RequireUserGesture(bool) changes the value.
173 bool require_user_gesture_; 167 bool require_user_gesture_;
174 168
175 // Factory to be used to create views when needed. 169 // Factory to be used to create views when needed.
176 PermissionBubbleView::Factory view_factory_; 170 // TODO(hcarmona): Investigate not using a factory, currently used for tests.
177 171 base::Callback<scoped_ptr<BubbleUI>(PermissionBubbleManager*)> ui_factory_;
178 // The UI surface to be used to display the permissions requests. 172 BubbleReference active_bubble_;
179 scoped_ptr<PermissionBubbleView> view_;
180 173
181 std::vector<PermissionBubbleRequest*> requests_; 174 std::vector<PermissionBubbleRequest*> requests_;
182 std::vector<PermissionBubbleRequest*> queued_requests_; 175 std::vector<PermissionBubbleRequest*> queued_requests_;
183 std::vector<PermissionBubbleRequest*> queued_frame_requests_; 176 std::vector<PermissionBubbleRequest*> queued_frame_requests_;
184 177
185 // URL of the main frame in the WebContents to which this manager is attached. 178 // URL of the main frame in the WebContents to which this manager is attached.
186 // TODO(gbillock): if there are iframes in the page, we need to deal with it. 179 // TODO(gbillock): if there are iframes in the page, we need to deal with it.
187 GURL request_url_; 180 GURL request_url_;
188 bool main_frame_has_fully_loaded_; 181 bool main_frame_has_fully_loaded_;
189 182
190 std::vector<bool> accept_states_; 183 std::vector<bool> accept_states_;
191 184
192 base::ObserverList<Observer> observer_list_; 185 base::ObserverList<Observer> observer_list_;
193 AutoResponseType auto_response_for_test_; 186 AutoResponseType auto_response_for_test_;
194 187
195 base::WeakPtrFactory<PermissionBubbleManager> weak_factory_; 188 base::WeakPtrFactory<PermissionBubbleManager> weak_factory_;
189
190 DISALLOW_COPY_AND_ASSIGN(PermissionBubbleManager);
196 }; 191 };
197 192
198 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_ 193 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698