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