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

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

Issue 1154943008: Update push messaging tests to use both infobars and bubbles (w/ autoresponse) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Put the auto-responder directly into the PermissionBubbleManager Created 5 years, 6 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/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "base/observer_list.h"
msw 2015/06/05 01:52:00 Remove this
felt 2015/06/05 06:37:29 Done.
11 #include "chrome/browser/ui/website_settings/permission_bubble_view.h" 12 #include "chrome/browser/ui/website_settings/permission_bubble_view.h"
12 #include "content/public/browser/web_contents_observer.h" 13 #include "content/public/browser/web_contents_observer.h"
13 #include "content/public/browser/web_contents_user_data.h" 14 #include "content/public/browser/web_contents_user_data.h"
14 15
15 class PermissionBubbleRequest; 16 class PermissionBubbleRequest;
16 17
17 // Provides access to permissions bubbles. Allows clients to add a request 18 // Provides access to permissions bubbles. Allows clients to add a request
18 // callback interface to the existing permission bubble configuration. 19 // callback interface to the existing permission bubble configuration.
19 // Depending on the situation and policy, that may add new UI to an existing 20 // Depending on the situation and policy, that may add new UI to an existing
20 // permission bubble, create and show a new permission bubble, or provide no 21 // permission bubble, create and show a new permission bubble, or provide no
21 // visible UI action at all. (In that case, the request will be immediately 22 // visible UI action at all. (In that case, the request will be immediately
22 // informed that the permission request failed.) 23 // informed that the permission request failed.)
23 // 24 //
24 // A PermissionBubbleManager is associated with a particular WebContents. 25 // A PermissionBubbleManager is associated with a particular WebContents.
25 // Requests attached to a particular WebContents' PBM must outlive it. 26 // Requests attached to a particular WebContents' PBM must outlive it.
26 // 27 //
27 // The PermissionBubbleManager should be addressed on the UI thread. 28 // The PermissionBubbleManager should be addressed on the UI thread.
28 class PermissionBubbleManager 29 class PermissionBubbleManager
29 : public content::WebContentsObserver, 30 : public content::WebContentsObserver,
30 public content::WebContentsUserData<PermissionBubbleManager>, 31 public content::WebContentsUserData<PermissionBubbleManager>,
31 public PermissionBubbleView::Delegate { 32 public PermissionBubbleView::Delegate {
32 public: 33 public:
34 class Observer {
msw 2015/06/05 01:52:00 Remove this.
felt 2015/06/05 06:37:29 Done.
35 public:
36 virtual ~Observer();
37 virtual void OnBubbleAdded();
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 22 matching lines...) Expand all
65 void RequireUserGesture(bool required); 72 void RequireUserGesture(bool required);
66 73
67 private: 74 private:
68 friend class DownloadRequestLimiterTest; 75 friend class DownloadRequestLimiterTest;
69 friend class GeolocationBrowserTest; 76 friend class GeolocationBrowserTest;
70 friend class GeolocationPermissionContextTests; 77 friend class GeolocationPermissionContextTests;
71 friend class GeolocationPermissionContextParamTests; 78 friend class GeolocationPermissionContextParamTests;
72 friend class PermissionBubbleManagerTest; 79 friend class PermissionBubbleManagerTest;
73 friend class PermissionContextBaseTests; 80 friend class PermissionContextBaseTests;
74 friend class content::WebContentsUserData<PermissionBubbleManager>; 81 friend class content::WebContentsUserData<PermissionBubbleManager>;
82 friend class PushMessagingBrowserTest;
msw 2015/06/05 01:52:00 Avoid friending by making the test setter public.
felt 2015/06/05 06:37:29 This makes me a little anxious... but I guess my c
83
84 enum AutoResponseType {
85 NOT_TESTING,
msw 2015/06/05 01:52:00 nit: maybe rename |NONE| (tests might want to clea
felt 2015/06/05 06:37:29 Done.
86 ACCEPT_ALL,
87 DENY_ALL,
88 DISMISS
89 };
75 90
76 explicit PermissionBubbleManager(content::WebContents* web_contents); 91 explicit PermissionBubbleManager(content::WebContents* web_contents);
77 92
78 // WebContentsObserver: 93 // WebContentsObserver:
79 void DocumentOnLoadCompletedInMainFrame() override; 94 void DocumentOnLoadCompletedInMainFrame() override;
80 void DocumentLoadedInFrame( 95 void DocumentLoadedInFrame(
81 content::RenderFrameHost* render_frame_host) override; 96 content::RenderFrameHost* render_frame_host) override;
82 97
83 // If a page on which permissions requests are pending is navigated, 98 // If a page on which permissions requests are pending is navigated,
84 // they will be finalized as if canceled by the user. 99 // they will be finalized as if canceled by the user.
(...skipping 27 matching lines...) Expand all
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 // Do NOT use these methods in production code. Use these methods in browser
138 // tests that need to accept or deny permissions when requested in
139 // JavaScript. Your test needs to set set_auto_response_for_testing_only_
140 // and then the bubble will proceed as desired as soon as Show() is called.
141 void set_auto_response_for_testing_only_(AutoResponseType response);
msw 2015/06/05 01:52:00 Name this |set_auto_response_for_test|.
felt 2015/06/05 06:37:29 Done.
142 void DoAutoResponseForTesting();
143
122 // Whether to delay displaying the bubble until a request with a user gesture. 144 // Whether to delay displaying the bubble until a request with a user gesture.
123 // False by default, unless RequireUserGesture(bool) changes the value. 145 // False by default, unless RequireUserGesture(bool) changes the value.
124 bool require_user_gesture_; 146 bool require_user_gesture_;
125 147
126 // Whether or not we are showing the bubble in this tab. 148 // Whether or not we are showing the bubble in this tab.
127 bool bubble_showing_; 149 bool bubble_showing_;
128 150
129 // Set to the UI surface to be used to display the permissions requests. 151 // Set to the UI surface to be used to display the permissions requests.
130 PermissionBubbleView* view_; 152 PermissionBubbleView* view_;
131 153
132 std::vector<PermissionBubbleRequest*> requests_; 154 std::vector<PermissionBubbleRequest*> requests_;
133 std::vector<PermissionBubbleRequest*> queued_requests_; 155 std::vector<PermissionBubbleRequest*> queued_requests_;
134 std::vector<PermissionBubbleRequest*> queued_frame_requests_; 156 std::vector<PermissionBubbleRequest*> queued_frame_requests_;
135 157
136 // URL of the main frame in the WebContents to which this manager is attached. 158 // 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. 159 // TODO(gbillock): if there are iframes in the page, we need to deal with it.
138 GURL request_url_; 160 GURL request_url_;
139 bool request_url_has_loaded_; 161 bool request_url_has_loaded_;
140 162
141 std::vector<bool> accept_states_; 163 std::vector<bool> accept_states_;
142 164
165 AutoResponseType auto_response_for_testing_only_;
msw 2015/06/05 01:52:00 Name this |auto_response_for_test_|
felt 2015/06/05 06:37:29 Done.
166
143 base::WeakPtrFactory<PermissionBubbleManager> weak_factory_; 167 base::WeakPtrFactory<PermissionBubbleManager> weak_factory_;
144 }; 168 };
145 169
146 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_ 170 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698