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

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

Issue 2081103002: Rename PermissionBubbleManager to PermissionRequestManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments Created 4 years, 5 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_
6 #define CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_
7
8 #include <unordered_map>
9 #include <vector>
10
11 #include "base/gtest_prod_util.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/observer_list.h"
14 #include "chrome/browser/ui/website_settings/permission_bubble_view.h"
15 #include "content/public/browser/web_contents_observer.h"
16 #include "content/public/browser/web_contents_user_data.h"
17
18 class PermissionBubbleRequest;
19
20 // Provides access to permissions bubbles. Allows clients to add a request
21 // callback interface to the existing permission bubble configuration.
22 // Depending on the situation and policy, that may add new UI to an existing
23 // permission bubble, create and show a new permission bubble, or provide no
24 // visible UI action at all. (In that case, the request will be immediately
25 // informed that the permission request failed.)
26 //
27 // A PermissionBubbleManager is associated with a particular WebContents.
28 // Requests attached to a particular WebContents' PBM must outlive it.
29 //
30 // The PermissionBubbleManager should be addressed on the UI thread.
31 class PermissionBubbleManager
32 : public content::WebContentsObserver,
33 public content::WebContentsUserData<PermissionBubbleManager>,
34 public PermissionBubbleView::Delegate {
35 public:
36 class Observer {
37 public:
38 virtual ~Observer();
39 virtual void OnBubbleAdded();
40 };
41
42 enum AutoResponseType {
43 NONE,
44 ACCEPT_ALL,
45 DENY_ALL,
46 DISMISS
47 };
48
49 ~PermissionBubbleManager() override;
50
51 // Adds a new request to the permission bubble. Ownership of the request
52 // remains with the caller. The caller must arrange for the request to
53 // outlive the PermissionBubbleManager. If a bubble is visible when this
54 // call is made, the request will be queued up and shown after the current
55 // bubble closes. A request with message text identical to an outstanding
56 // request will be merged with the outstanding request, and will have the same
57 // callbacks called as the outstanding request.
58 void AddRequest(PermissionBubbleRequest* request);
59
60 // Cancels an outstanding request. This may have different effects depending
61 // on what is going on with the bubble. If the request is pending, it will be
62 // removed and never shown. If the request is showing, it will continue to be
63 // shown, but the user's action won't be reported back to the request object.
64 // In some circumstances, we can remove the request from the bubble, and may
65 // do so. The request will have RequestFinished executed on it if it is found,
66 // at which time the caller is free to delete the request.
67 void CancelRequest(PermissionBubbleRequest* request);
68
69 // Hides the bubble.
70 void HideBubble();
71
72 // Will show a permission bubble if there is a pending permission request on
73 // the web contents that the PermissionBubbleManager belongs to.
74 void DisplayPendingRequests();
75
76 // Will reposition the bubble (may change parent if necessary).
77 void UpdateAnchorPosition();
78
79 // True if a permission bubble is currently visible.
80 // TODO(hcarmona): Remove this as part of the bubble API work.
81 bool IsBubbleVisible();
82
83 // Get the native window of the bubble.
84 // TODO(hcarmona): Remove this as part of the bubble API work.
85 gfx::NativeWindow GetBubbleWindow();
86
87 // For observing the status of the permission bubble manager.
88 void AddObserver(Observer* observer);
89 void RemoveObserver(Observer* observer);
90
91 // Do NOT use this methods in production code. Use this methods in browser
92 // tests that need to accept or deny permissions when requested in
93 // JavaScript. Your test needs to set this appropriately, and then the bubble
94 // will proceed as desired as soon as Show() is called.
95 void set_auto_response_for_test(AutoResponseType response) {
96 auto_response_for_test_ = response;
97 }
98
99 private:
100 // TODO(felt): Update testing so that it doesn't involve a lot of friends.
101 friend class GeolocationBrowserTest;
102 friend class GeolocationPermissionContextTests;
103 friend class MockPermissionBubbleFactory;
104 friend class MockPermissionBubbleView;
105 friend class PermissionBubbleManagerTest;
106 friend class PermissionContextBaseTests;
107 friend class content::WebContentsUserData<PermissionBubbleManager>;
108 FRIEND_TEST_ALL_PREFIXES(DownloadTest, TestMultipleDownloadsBubble);
109
110 explicit PermissionBubbleManager(content::WebContents* web_contents);
111
112 // WebContentsObserver:
113 void DidNavigateMainFrame(
114 const content::LoadCommittedDetails& details,
115 const content::FrameNavigateParams& params) override;
116 void DocumentOnLoadCompletedInMainFrame() override;
117 void DocumentLoadedInFrame(
118 content::RenderFrameHost* render_frame_host) override;
119 void WebContentsDestroyed() override;
120
121 // PermissionBubbleView::Delegate:
122 void ToggleAccept(int request_index, bool new_value) override;
123 void Accept() override;
124 void Deny() override;
125 void Closing() override;
126
127 // Posts a task which will allow the bubble to become visible if it is needed.
128 void ScheduleShowBubble();
129
130 // Shows the bubble if it is not already visible and there are pending
131 // requests.
132 void TriggerShowBubble();
133
134 // Finalize the pending permissions request.
135 void FinalizeBubble();
136
137 // Cancel any pending requests. This is called if the WebContents
138 // on which permissions calls are pending is destroyed or navigated away
139 // from the requesting page.
140 void CancelPendingQueues();
141
142 // Searches |requests_|, |queued_requests_| and |queued_frame_requests_| - but
143 // *not* |duplicate_requests_| - for a request matching |request|, and returns
144 // the matching request, or |nullptr| if no match. Note that the matching
145 // request may or may not be the same object as |request|.
146 PermissionBubbleRequest* GetExistingRequest(PermissionBubbleRequest* request);
147
148 // Returns true if |queue| contains a request which was generated by a user
149 // gesture. Returns false otherwise.
150 bool HasUserGestureRequest(
151 const std::vector<PermissionBubbleRequest*>& queue);
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
162 void NotifyBubbleAdded();
163
164 void DoAutoResponseForTesting();
165
166 // Factory to be used to create views when needed.
167 PermissionBubbleView::Factory view_factory_;
168
169 // The UI surface to be used to display the permissions requests.
170 std::unique_ptr<PermissionBubbleView> view_;
171
172 std::vector<PermissionBubbleRequest*> requests_;
173 std::vector<PermissionBubbleRequest*> queued_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_;
179
180 // URL of the main frame in the WebContents to which this manager is attached.
181 // TODO(gbillock): if there are iframes in the page, we need to deal with it.
182 GURL request_url_;
183 bool main_frame_has_fully_loaded_;
184
185 // Whether each of the requests in |requests_| is accepted by the user.
186 std::vector<bool> accept_states_;
187
188 base::ObserverList<Observer> observer_list_;
189 AutoResponseType auto_response_for_test_;
190
191 base::WeakPtrFactory<PermissionBubbleManager> weak_factory_;
192 };
193
194 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698