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_
10 #include "base/timer/timer.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
{
33 // Return the flag-driven enabled state of permissions bubbles.
34 static bool Enabled();
36 virtual ~PermissionBubbleManager();
38 // Adds a new request to the permission bubble. Ownership of the request
39 // remains with the caller. The caller must arrange for the request to
40 // outlive the PermissionBubbleManager. If a bubble is visible when this
41 // call is made, the request will be queued up and shown after the current
42 // bubble closes. A request with message text identical to an outstanding
43 // request will receive a RequestFinished call immediately and not be added.
44 virtual void AddRequest(PermissionBubbleRequest
* request
);
46 // Cancels an outstanding request. This may have different effects depending
47 // on what is going on with the bubble. If the request is pending, it will be
48 // removed and never shown. If the request is showing, it will continue to be
49 // shown, but the user's action won't be reported back to the request object.
50 // In some circumstances, we can remove the request from the bubble, and may
51 // do so. The caller may delete the request after calling this method.
52 virtual void CancelRequest(PermissionBubbleRequest
* request
);
54 // Sets the active view for the permission bubble. If this is NULL, it
55 // means any existing permission bubble can no longer be shown. Does not
56 // take ownership of the view.
57 virtual void SetView(PermissionBubbleView
* view
) OVERRIDE
;
60 // Sets the coalesce time interval to |interval_ms|. For testing only.
61 void SetCoalesceIntervalForTesting(int interval_ms
);
64 friend class PermissionBubbleManagerTest
;
65 friend class DownloadRequestLimiterTest
;
66 friend class content::WebContentsUserData
<PermissionBubbleManager
>;
68 explicit PermissionBubbleManager(content::WebContents
* web_contents
);
70 // contents::WebContentsObserver:
71 // TODO(leng): Investigate the ordering and timing of page loading and
72 // permission requests with iFrames. DocumentOnLoadCompletedInMainFrame()
73 // and DocumentLoadedInFrame() might be needed as well.
74 virtual void DidFinishLoad(
76 const GURL
& validated_url
,
78 content::RenderViewHost
* render_view_host
) OVERRIDE
;
79 virtual void WebContentsDestroyed(
80 content::WebContents
* web_contents
) OVERRIDE
;
82 // PermissionBubbleView::Delegate:
83 virtual void ToggleAccept(int request_index
, bool new_value
) OVERRIDE
;
84 virtual void SetCustomizationMode() OVERRIDE
;
85 virtual void Accept() OVERRIDE
;
86 virtual void Deny() OVERRIDE
;
87 virtual void Closing() OVERRIDE
;
89 // Called when the coalescing timer is done. Presents the bubble.
92 // Finalize the pending permissions request.
93 void FinalizeBubble();
95 // Whether or not we are showing the bubble in this tab.
98 // Set to the UI surface to be used to display the permissions requests.
99 PermissionBubbleView
* view_
;
101 std::vector
<PermissionBubbleRequest
*> requests_
;
102 std::vector
<PermissionBubbleRequest
*> queued_requests_
;
103 std::vector
<bool> accept_states_
;
104 bool customization_mode_
;
106 scoped_ptr
<base::Timer
> timer_
;
109 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_