Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / website_settings / permission_bubble_manager.h
blob1c624b66f09a130df079e6db52d8a8e68d2960e0
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.
5 #ifndef CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_
6 #define CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_
8 #include <vector>
10 #include "base/memory/weak_ptr.h"
11 #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_user_data.h"
15 class PermissionBubbleRequest;
17 // Provides access to permissions bubbles. Allows clients to add a request
18 // callback interface to the existing permission bubble configuration.
19 // 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 // visible UI action at all. (In that case, the request will be immediately
22 // informed that the permission request failed.)
24 // A PermissionBubbleManager is associated with a particular WebContents.
25 // Requests attached to a particular WebContents' PBM must outlive it.
27 // The PermissionBubbleManager should be addressed on the UI thread.
28 class PermissionBubbleManager
29 : public content::WebContentsObserver,
30 public content::WebContentsUserData<PermissionBubbleManager>,
31 public PermissionBubbleView::Delegate {
32 public:
33 // Return the enabled state of permissions bubbles.
34 // Controlled by a flag and FieldTrial.
35 static bool Enabled();
37 ~PermissionBubbleManager() override;
39 // 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
41 // 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
43 // bubble closes. A request with message text identical to an outstanding
44 // request will receive a RequestFinished call immediately and not be added.
45 virtual void AddRequest(PermissionBubbleRequest* request);
47 // Cancels an outstanding request. This may have different effects depending
48 // on what is going on with the bubble. If the request is pending, it will be
49 // removed and never shown. If the request is showing, it will continue to be
50 // shown, but the user's action won't be reported back to the request object.
51 // In some circumstances, we can remove the request from the bubble, and may
52 // do so. The request will have RequestFinished executed on it if it is found,
53 // at which time the caller is free to delete the request.
54 virtual void CancelRequest(PermissionBubbleRequest* request);
56 // Sets the active view for the permission bubble. If this is NULL, it
57 // means any existing permission bubble can no longer be shown. Does not
58 // take ownership of the view.
59 void SetView(PermissionBubbleView* view) override;
61 // Controls whether incoming permission requests require user gestures.
62 // If |required| is false, requests will be displayed as soon as they come in.
63 // If |required| is true, requests will be silently queued until a request
64 // comes in with a user gesture.
65 void RequireUserGesture(bool required);
67 private:
68 friend class DownloadRequestLimiterTest;
69 friend class GeolocationBrowserTest;
70 friend class GeolocationPermissionContextTests;
71 friend class GeolocationPermissionContextParamTests;
72 friend class PermissionBubbleManagerTest;
73 friend class PermissionContextBaseTests;
74 friend class content::WebContentsUserData<PermissionBubbleManager>;
76 explicit PermissionBubbleManager(content::WebContents* web_contents);
78 // WebContentsObserver:
79 void DocumentOnLoadCompletedInMainFrame() override;
80 void DocumentLoadedInFrame(
81 content::RenderFrameHost* render_frame_host) override;
83 // If a page on which permissions requests are pending is navigated,
84 // they will be finalized as if canceled by the user.
85 void NavigationEntryCommitted(
86 const content::LoadCommittedDetails& details) override;
87 void WebContentsDestroyed() override;
89 // PermissionBubbleView::Delegate:
90 void ToggleAccept(int request_index, bool new_value) override;
91 void Accept() override;
92 void Deny() override;
93 void Closing() override;
95 // Posts a task which will allow the bubble to become visible if it is needed.
96 void ScheduleShowBubble();
98 // Shows the bubble if it is not already visible and there are pending
99 // requests.
100 void TriggerShowBubble();
102 // Finalize the pending permissions request.
103 void FinalizeBubble();
105 // Cancel any pending requests. This is called if the WebContents
106 // on which permissions calls are pending is destroyed or navigated away
107 // from the requesting page.
108 void CancelPendingQueues();
110 // Returns whether or not |request| has already been added to |queue|.
111 // |same_object| must be non-null. It will be set to true if |request|
112 // is the same object as an existing request in |queue|, false otherwise.
113 bool ExistingRequest(PermissionBubbleRequest* request,
114 const std::vector<PermissionBubbleRequest*>& queue,
115 bool* same_object);
117 // Returns true if |queue| contains a request which was generated by a user
118 // gesture. Returns false otherwise.
119 bool HasUserGestureRequest(
120 const std::vector<PermissionBubbleRequest*>& queue);
122 // Whether to delay displaying the bubble until a request with a user gesture.
123 // False by default, unless RequireUserGesture(bool) changes the value.
124 bool require_user_gesture_;
126 // Whether or not we are showing the bubble in this tab.
127 bool bubble_showing_;
129 // Set to the UI surface to be used to display the permissions requests.
130 PermissionBubbleView* view_;
132 std::vector<PermissionBubbleRequest*> requests_;
133 std::vector<PermissionBubbleRequest*> queued_requests_;
134 std::vector<PermissionBubbleRequest*> queued_frame_requests_;
136 // 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.
138 GURL request_url_;
139 bool request_url_has_loaded_;
141 std::vector<bool> accept_states_;
143 base::WeakPtrFactory<PermissionBubbleManager> weak_factory_;
146 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_