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

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: Update 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
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 // Will show a permission bubble if there is a pending permission request on
75 // the web contents that the PermissionBubbleManager belongs to. 76 // the web contents that the PermissionBubbleManager belongs to.
76 void DisplayPendingRequests(Browser* browser); 77 void DisplayPendingRequests();
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 78
89 // Controls whether incoming permission requests require user gestures. 79 // Controls whether incoming permission requests require user gestures.
90 // If |required| is false, requests will be displayed as soon as they come in. 80 // 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 81 // If |required| is true, requests will be silently queued until a request
92 // comes in with a user gesture. 82 // comes in with a user gesture.
93 void RequireUserGesture(bool required); 83 void RequireUserGesture(bool required);
94 84
95 // For observing the status of the permission bubble manager. 85 // For observing the status of the permission bubble manager.
96 void AddObserver(Observer* observer); 86 void AddObserver(Observer* observer);
97 void RemoveObserver(Observer* observer); 87 void RemoveObserver(Observer* observer);
98 88
99 // Do NOT use this methods in production code. Use this methods in browser 89 // 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 90 // tests that need to accept or deny permissions when requested in
101 // JavaScript. Your test needs to set this appropriately, and then the bubble 91 // JavaScript. Your test needs to set this appropriately, and then the bubble
102 // will proceed as desired as soon as Show() is called. 92 // will proceed as desired as soon as Show() is called.
103 void set_auto_response_for_test(AutoResponseType response) { 93 void set_auto_response_for_test(AutoResponseType response) {
104 auto_response_for_test_ = response; 94 auto_response_for_test_ = response;
105 } 95 }
106 96
97 const std::vector<PermissionBubbleRequest*>& requests() { return requests_; }
98
99 const std::vector<bool>& accept_states() { return accept_states_; }
100
101 Browser* browser() { return browser_; }
102
103 void ToggleAccept(int request_index, bool new_value);
104 void Accept();
105 void Deny();
106 void Closing();
107
107 private: 108 private:
108 // TODO(felt): Update testing so that it doesn't involve a lot of friends. 109 // TODO(felt): Update testing so that it doesn't involve a lot of friends.
109 friend class DownloadRequestLimiterTest; 110 friend class DownloadRequestLimiterTest;
110 friend class GeolocationBrowserTest; 111 friend class GeolocationBrowserTest;
111 friend class GeolocationPermissionContextTests; 112 friend class GeolocationPermissionContextTests;
112 friend class MockPermissionBubbleView; 113 friend class MockPermissionBubbleView;
113 friend class PermissionBubbleManagerTest; 114 friend class PermissionBubbleManagerTest;
114 friend class PermissionContextBaseTests; 115 friend class PermissionContextBaseTests;
115 friend class content::WebContentsUserData<PermissionBubbleManager>; 116 friend class content::WebContentsUserData<PermissionBubbleManager>;
116 FRIEND_TEST_ALL_PREFIXES(DownloadTest, TestMultipleDownloadsBubble); 117 FRIEND_TEST_ALL_PREFIXES(DownloadTest, TestMultipleDownloadsBubble);
117 118
118 explicit PermissionBubbleManager(content::WebContents* web_contents); 119 explicit PermissionBubbleManager(content::WebContents* web_contents);
119 120
120 // WebContentsObserver: 121 // WebContentsObserver:
121 void DidNavigateMainFrame( 122 void DidNavigateMainFrame(
122 const content::LoadCommittedDetails& details, 123 const content::LoadCommittedDetails& details,
123 const content::FrameNavigateParams& params) override; 124 const content::FrameNavigateParams& params) override;
124 void DocumentOnLoadCompletedInMainFrame() override; 125 void DocumentOnLoadCompletedInMainFrame() override;
125 void DocumentLoadedInFrame( 126 void DocumentLoadedInFrame(
126 content::RenderFrameHost* render_frame_host) override; 127 content::RenderFrameHost* render_frame_host) override;
127 128
128 // If a page on which permissions requests are pending is navigated, 129 // If a page on which permissions requests are pending is navigated,
129 // they will be finalized as if canceled by the user. 130 // they will be finalized as if canceled by the user.
130 void NavigationEntryCommitted( 131 void NavigationEntryCommitted(
131 const content::LoadCommittedDetails& details) override; 132 const content::LoadCommittedDetails& details) override;
132 void WebContentsDestroyed() override; 133 void WebContentsDestroyed() override;
133 134
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. 135 // Posts a task which will allow the bubble to become visible if it is needed.
141 void ScheduleShowBubble(); 136 void ScheduleShowBubble();
142 137
143 // Shows the bubble if it is not already visible and there are pending 138 // Shows the bubble if it is not already visible and there are pending
144 // requests. 139 // requests.
145 void TriggerShowBubble(); 140 void TriggerShowBubble();
146 141
147 // Finalize the pending permissions request. 142 // Finalize the pending permissions request.
148 void FinalizeBubble(); 143 void FinalizeBubble();
149 144
145 // Hides the bubble.
146 void HideBubble();
147
150 // Cancel any pending requests. This is called if the WebContents 148 // Cancel any pending requests. This is called if the WebContents
151 // on which permissions calls are pending is destroyed or navigated away 149 // on which permissions calls are pending is destroyed or navigated away
152 // from the requesting page. 150 // from the requesting page.
153 void CancelPendingQueues(); 151 void CancelPendingQueues();
154 152
155 // Returns whether or not |request| has already been added to |queue|. 153 // 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| 154 // |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. 155 // is the same object as an existing request in |queue|, false otherwise.
158 bool ExistingRequest(PermissionBubbleRequest* request, 156 bool ExistingRequest(PermissionBubbleRequest* request,
159 const std::vector<PermissionBubbleRequest*>& queue, 157 const std::vector<PermissionBubbleRequest*>& queue,
160 bool* same_object); 158 bool* same_object);
161 159
162 // Returns true if |queue| contains a request which was generated by a user 160 // Returns true if |queue| contains a request which was generated by a user
163 // gesture. Returns false otherwise. 161 // gesture. Returns false otherwise.
164 bool HasUserGestureRequest( 162 bool HasUserGestureRequest(
165 const std::vector<PermissionBubbleRequest*>& queue); 163 const std::vector<PermissionBubbleRequest*>& queue);
166 164
167 void NotifyBubbleAdded(); 165 void NotifyBubbleAdded();
168 166
169 void DoAutoResponseForTesting(); 167 void DoAutoResponseForTesting();
170 168
169 // True if a permission bubble is currently visible.
170 bool IsBubbleVisible();
171
171 // Whether to delay displaying the bubble until a request with a user gesture. 172 // Whether to delay displaying the bubble until a request with a user gesture.
172 // False by default, unless RequireUserGesture(bool) changes the value. 173 // False by default, unless RequireUserGesture(bool) changes the value.
173 bool require_user_gesture_; 174 bool require_user_gesture_;
174 175
175 // Factory to be used to create views when needed. 176 // Factory to be used to create views when needed.
176 PermissionBubbleView::Factory view_factory_; 177 PermissionBubbleView::Factory view_factory_;
177 178 BubbleReference active_bubble_;
178 // The UI surface to be used to display the permissions requests.
179 scoped_ptr<PermissionBubbleView> view_;
180 179
181 std::vector<PermissionBubbleRequest*> requests_; 180 std::vector<PermissionBubbleRequest*> requests_;
182 std::vector<PermissionBubbleRequest*> queued_requests_; 181 std::vector<PermissionBubbleRequest*> queued_requests_;
183 std::vector<PermissionBubbleRequest*> queued_frame_requests_; 182 std::vector<PermissionBubbleRequest*> queued_frame_requests_;
184 183
185 // 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.
186 // 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.
187 GURL request_url_; 186 GURL request_url_;
188 bool main_frame_has_fully_loaded_; 187 bool main_frame_has_fully_loaded_;
189 188
190 std::vector<bool> accept_states_; 189 std::vector<bool> accept_states_;
191 190
192 base::ObserverList<Observer> observer_list_; 191 base::ObserverList<Observer> observer_list_;
193 AutoResponseType auto_response_for_test_; 192 AutoResponseType auto_response_for_test_;
194 193
194 Browser* browser_;
195
195 base::WeakPtrFactory<PermissionBubbleManager> weak_factory_; 196 base::WeakPtrFactory<PermissionBubbleManager> weak_factory_;
196 }; 197 };
197 198
198 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_ 199 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698