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

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 "chrome/browser/ui/website_settings/permission_bubble_view.h"
14 #include "components/bubble/bubble_manager.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
18 class Browser;
17 class PermissionBubbleRequest; 19 class PermissionBubbleRequest;
18 20
19 // Provides access to permissions bubbles. Allows clients to add a request 21 // Provides access to permissions bubbles. Allows clients to add a request
20 // callback interface to the existing permission bubble configuration. 22 // callback interface to the existing permission bubble configuration.
21 // Depending on the situation and policy, that may add new UI to an existing 23 // 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 24 // 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 25 // visible UI action at all. (In that case, the request will be immediately
24 // informed that the permission request failed.) 26 // informed that the permission request failed.)
25 // 27 //
26 // A PermissionBubbleManager is associated with a particular WebContents. 28 // A PermissionBubbleManager is associated with a particular WebContents.
27 // Requests attached to a particular WebContents' PBM must outlive it. 29 // Requests attached to a particular WebContents' PBM must outlive it.
28 // 30 //
29 // The PermissionBubbleManager should be addressed on the UI thread. 31 // The PermissionBubbleManager should be addressed on the UI thread.
30 class PermissionBubbleManager 32 class PermissionBubbleManager
hcarmona 2015/08/06 20:34:10 This class should be renamed to PermissionRequestQ
31 : public content::WebContentsObserver, 33 : public content::WebContentsObserver,
32 public content::WebContentsUserData<PermissionBubbleManager>, 34 public content::WebContentsUserData<PermissionBubbleManager> {
33 public PermissionBubbleView::Delegate {
34 public: 35 public:
35 class Observer { 36 class Observer {
36 public: 37 public:
37 virtual ~Observer(); 38 virtual ~Observer();
38 virtual void OnBubbleAdded(); 39 virtual void OnBubbleAdded();
39 }; 40 };
40 41
41 enum AutoResponseType { 42 enum AutoResponseType {
42 NONE, 43 NONE,
43 ACCEPT_ALL, 44 ACCEPT_ALL,
44 DENY_ALL, 45 DENY_ALL,
45 DISMISS 46 DISMISS
46 }; 47 };
47 48
48 // Return the enabled state of permissions bubbles. 49 // Return the enabled state of permissions bubbles.
49 // Controlled by a flag and FieldTrial. 50 // Controlled by a flag and FieldTrial.
50 static bool Enabled(); 51 static bool Enabled();
51 52
52 ~PermissionBubbleManager() override; 53 ~PermissionBubbleManager() override;
53 54
55 // Associte this instnce with a browser.
56 void SetBrowser(Browser* browser) { browser_ = browser; }
57
54 // Adds a new request to the permission bubble. Ownership of the request 58 // Adds a new request to the permission bubble. Ownership of the request
55 // remains with the caller. The caller must arrange for the request to 59 // remains with the caller. The caller must arrange for the request to
56 // outlive the PermissionBubbleManager. If a bubble is visible when this 60 // outlive the PermissionBubbleManager. If a bubble is visible when this
57 // call is made, the request will be queued up and shown after the current 61 // call is made, the request will be queued up and shown after the current
58 // bubble closes. A request with message text identical to an outstanding 62 // bubble closes. A request with message text identical to an outstanding
59 // request will receive a RequestFinished call immediately and not be added. 63 // request will receive a RequestFinished call immediately and not be added.
60 virtual void AddRequest(PermissionBubbleRequest* request); 64 virtual void AddRequest(PermissionBubbleRequest* request);
61 65
62 // Cancels an outstanding request. This may have different effects depending 66 // 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 67 // 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 68 // 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. 69 // 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 70 // 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, 71 // 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. 72 // at which time the caller is free to delete the request.
69 virtual void CancelRequest(PermissionBubbleRequest* request); 73 virtual void CancelRequest(PermissionBubbleRequest* request);
70 74
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. 75 // Controls whether incoming permission requests require user gestures.
90 // If |required| is false, requests will be displayed as soon as they come in. 76 // 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 77 // If |required| is true, requests will be silently queued until a request
92 // comes in with a user gesture. 78 // comes in with a user gesture.
93 void RequireUserGesture(bool required); 79 void RequireUserGesture(bool required);
94 80
95 // For observing the status of the permission bubble manager. 81 // For observing the status of the permission bubble manager.
96 void AddObserver(Observer* observer); 82 void AddObserver(Observer* observer);
97 void RemoveObserver(Observer* observer); 83 void RemoveObserver(Observer* observer);
98 84
99 // Do NOT use this methods in production code. Use this methods in browser 85 // 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 86 // tests that need to accept or deny permissions when requested in
101 // JavaScript. Your test needs to set this appropriately, and then the bubble 87 // JavaScript. Your test needs to set this appropriately, and then the bubble
102 // will proceed as desired as soon as Show() is called. 88 // will proceed as desired as soon as Show() is called.
103 void set_auto_response_for_test(AutoResponseType response) { 89 void set_auto_response_for_test(AutoResponseType response) {
104 auto_response_for_test_ = response; 90 auto_response_for_test_ = response;
105 } 91 }
106 92
93 const std::vector<PermissionBubbleRequest*>& requests() { return requests_; }
94
95 const std::vector<bool>& accept_states() { return accept_states_; }
96
97 Browser* browser() { return browser_; }
98
99 void ToggleAccept(int request_index, bool new_value);
100 void Accept();
101 void Deny();
102 void Closing();
103
104 // Finalize the pending permissions. Called after the bubble is closed.
105 void Finalize();
106
107 private: 107 private:
108 // TODO(felt): Update testing so that it doesn't involve a lot of friends. 108 // TODO(felt): Update testing so that it doesn't involve a lot of friends.
109 friend class DownloadRequestLimiterTest; 109 friend class DownloadRequestLimiterTest;
110 friend class GeolocationBrowserTest; 110 friend class GeolocationBrowserTest;
111 friend class GeolocationPermissionContextTests; 111 friend class GeolocationPermissionContextTests;
112 friend class MockPermissionBubbleView; 112 friend class MockPermissionBubbleView;
113 friend class PermissionBubbleManagerTest; 113 friend class PermissionBubbleManagerTest;
114 friend class PermissionContextBaseTests; 114 friend class PermissionContextBaseTests;
115 friend class content::WebContentsUserData<PermissionBubbleManager>; 115 friend class content::WebContentsUserData<PermissionBubbleManager>;
116 FRIEND_TEST_ALL_PREFIXES(DownloadTest, TestMultipleDownloadsBubble); 116 FRIEND_TEST_ALL_PREFIXES(DownloadTest, TestMultipleDownloadsBubble);
117 117
118 explicit PermissionBubbleManager(content::WebContents* web_contents); 118 explicit PermissionBubbleManager(content::WebContents* web_contents);
119 119
120 // WebContentsObserver: 120 // WebContentsObserver:
121 void DidNavigateMainFrame( 121 void DidNavigateMainFrame(
122 const content::LoadCommittedDetails& details, 122 const content::LoadCommittedDetails& details,
123 const content::FrameNavigateParams& params) override; 123 const content::FrameNavigateParams& params) override;
124 void DocumentOnLoadCompletedInMainFrame() override; 124 void DocumentOnLoadCompletedInMainFrame() override;
125 void DocumentLoadedInFrame( 125 void DocumentLoadedInFrame(
126 content::RenderFrameHost* render_frame_host) override; 126 content::RenderFrameHost* render_frame_host) override;
127 127
128 // If a page on which permissions requests are pending is navigated, 128 // If a page on which permissions requests are pending is navigated,
129 // they will be finalized as if canceled by the user. 129 // they will be finalized as if canceled by the user.
130 void NavigationEntryCommitted( 130 void NavigationEntryCommitted(
131 const content::LoadCommittedDetails& details) override; 131 const content::LoadCommittedDetails& details) override;
132 void WebContentsDestroyed() override; 132 void WebContentsDestroyed() override;
133 133
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();
142
143 // Shows the bubble if it is not already visible and there are pending 134 // Shows the bubble if it is not already visible and there are pending
144 // requests. 135 // requests.
145 void TriggerShowBubble(); 136 void TriggerShowBubble();
146 137
147 // Finalize the pending permissions request. 138 // Closes the bubble.
148 void FinalizeBubble(); 139 void CloseBubble();
149 140
150 // Cancel any pending requests. This is called if the WebContents 141 // Cancel any pending requests. This is called if the WebContents
151 // on which permissions calls are pending is destroyed or navigated away 142 // on which permissions calls are pending is destroyed or navigated away
152 // from the requesting page. 143 // from the requesting page.
153 void CancelPendingQueues(); 144 void CancelPendingQueues();
154 145
155 // Returns whether or not |request| has already been added to |queue|. 146 // 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| 147 // |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. 148 // is the same object as an existing request in |queue|, false otherwise.
158 bool ExistingRequest(PermissionBubbleRequest* request, 149 bool ExistingRequest(PermissionBubbleRequest* request,
159 const std::vector<PermissionBubbleRequest*>& queue, 150 const std::vector<PermissionBubbleRequest*>& queue,
160 bool* same_object); 151 bool* same_object);
161 152
162 // Returns true if |queue| contains a request which was generated by a user 153 // Returns true if |queue| contains a request which was generated by a user
163 // gesture. Returns false otherwise. 154 // gesture. Returns false otherwise.
164 bool HasUserGestureRequest( 155 bool HasUserGestureRequest(
165 const std::vector<PermissionBubbleRequest*>& queue); 156 const std::vector<PermissionBubbleRequest*>& queue);
166 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 PermissionBubbleView::Factory view_factory_;
177 171 BubbleReference active_bubble_;
178 // The UI surface to be used to display the permissions requests.
179 scoped_ptr<PermissionBubbleView> view_;
180 172
181 std::vector<PermissionBubbleRequest*> requests_; 173 std::vector<PermissionBubbleRequest*> requests_;
182 std::vector<PermissionBubbleRequest*> queued_requests_; 174 std::vector<PermissionBubbleRequest*> queued_requests_;
183 std::vector<PermissionBubbleRequest*> queued_frame_requests_; 175 std::vector<PermissionBubbleRequest*> queued_frame_requests_;
184 176
185 // URL of the main frame in the WebContents to which this manager is attached. 177 // 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. 178 // TODO(gbillock): if there are iframes in the page, we need to deal with it.
187 GURL request_url_; 179 GURL request_url_;
188 bool main_frame_has_fully_loaded_; 180 bool main_frame_has_fully_loaded_;
189 181
190 std::vector<bool> accept_states_; 182 std::vector<bool> accept_states_;
191 183
192 base::ObserverList<Observer> observer_list_; 184 base::ObserverList<Observer> observer_list_;
193 AutoResponseType auto_response_for_test_; 185 AutoResponseType auto_response_for_test_;
194 186
187 Browser* browser_;
188
195 base::WeakPtrFactory<PermissionBubbleManager> weak_factory_; 189 base::WeakPtrFactory<PermissionBubbleManager> weak_factory_;
190
191 DISALLOW_COPY_AND_ASSIGN(PermissionBubbleManager);
196 }; 192 };
197 193
198 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_ 194 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698