| 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/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/observer_list.h" |
| 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 { |
| 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 Loading... |
| 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 PermissionBubbleResponder; |
| 75 | 83 |
| 76 explicit PermissionBubbleManager(content::WebContents* web_contents); | 84 explicit PermissionBubbleManager(content::WebContents* web_contents); |
| 77 | 85 |
| 78 // WebContentsObserver: | 86 // WebContentsObserver: |
| 79 void DocumentOnLoadCompletedInMainFrame() override; | 87 void DocumentOnLoadCompletedInMainFrame() override; |
| 80 void DocumentLoadedInFrame( | 88 void DocumentLoadedInFrame( |
| 81 content::RenderFrameHost* render_frame_host) override; | 89 content::RenderFrameHost* render_frame_host) override; |
| 82 | 90 |
| 83 // If a page on which permissions requests are pending is navigated, | 91 // If a page on which permissions requests are pending is navigated, |
| 84 // they will be finalized as if canceled by the user. | 92 // they will be finalized as if canceled by the user. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 112 // is the same object as an existing request in |queue|, false otherwise. | 120 // is the same object as an existing request in |queue|, false otherwise. |
| 113 bool ExistingRequest(PermissionBubbleRequest* request, | 121 bool ExistingRequest(PermissionBubbleRequest* request, |
| 114 const std::vector<PermissionBubbleRequest*>& queue, | 122 const std::vector<PermissionBubbleRequest*>& queue, |
| 115 bool* same_object); | 123 bool* same_object); |
| 116 | 124 |
| 117 // Returns true if |queue| contains a request which was generated by a user | 125 // Returns true if |queue| contains a request which was generated by a user |
| 118 // gesture. Returns false otherwise. | 126 // gesture. Returns false otherwise. |
| 119 bool HasUserGestureRequest( | 127 bool HasUserGestureRequest( |
| 120 const std::vector<PermissionBubbleRequest*>& queue); | 128 const std::vector<PermissionBubbleRequest*>& queue); |
| 121 | 129 |
| 130 void AddObserver(Observer* obs); |
| 131 void RemoveObserver(Observer* obs); |
| 132 void NotifyBubbleAdded(PermissionBubbleView* bubble); |
| 133 |
| 122 // Whether to delay displaying the bubble until a request with a user gesture. | 134 // Whether to delay displaying the bubble until a request with a user gesture. |
| 123 // False by default, unless RequireUserGesture(bool) changes the value. | 135 // False by default, unless RequireUserGesture(bool) changes the value. |
| 124 bool require_user_gesture_; | 136 bool require_user_gesture_; |
| 125 | 137 |
| 126 // Whether or not we are showing the bubble in this tab. | 138 // Whether or not we are showing the bubble in this tab. |
| 127 bool bubble_showing_; | 139 bool bubble_showing_; |
| 128 | 140 |
| 129 // Set to the UI surface to be used to display the permissions requests. | 141 // Set to the UI surface to be used to display the permissions requests. |
| 130 PermissionBubbleView* view_; | 142 PermissionBubbleView* view_; |
| 131 | 143 |
| 132 std::vector<PermissionBubbleRequest*> requests_; | 144 std::vector<PermissionBubbleRequest*> requests_; |
| 133 std::vector<PermissionBubbleRequest*> queued_requests_; | 145 std::vector<PermissionBubbleRequest*> queued_requests_; |
| 134 std::vector<PermissionBubbleRequest*> queued_frame_requests_; | 146 std::vector<PermissionBubbleRequest*> queued_frame_requests_; |
| 135 | 147 |
| 136 // URL of the main frame in the WebContents to which this manager is attached. | 148 // 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. | 149 // TODO(gbillock): if there are iframes in the page, we need to deal with it. |
| 138 GURL request_url_; | 150 GURL request_url_; |
| 139 bool request_url_has_loaded_; | 151 bool request_url_has_loaded_; |
| 140 | 152 |
| 141 std::vector<bool> accept_states_; | 153 std::vector<bool> accept_states_; |
| 142 | 154 |
| 155 ObserverList<Observer> observer_list_; |
| 156 |
| 143 base::WeakPtrFactory<PermissionBubbleManager> weak_factory_; | 157 base::WeakPtrFactory<PermissionBubbleManager> weak_factory_; |
| 144 }; | 158 }; |
| 145 | 159 |
| 146 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_ | 160 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_ |
| OLD | NEW |